Interface IStateMessage
Interface with IMessage and INotifyPropertyChanged to hold a message and show if necessary.
public interface IStateMessage : IMessage, ITranslatableText, INotifyPropertyChanged
- Inherited Members
Examples
This example shows a warning when a fuse is tripped, meaning a digital input is low.
internal class FuseIsTrippedStateMessage : MessageBase, IStateMessage
{
private readonly IDigitalInput _input;
public FuseIsTrippedStateMessage(IDigitalInput input)
: base(new StaticTranslation("A fuse is tripped."), LogLevel.Warn)
{
_input = input ?? throw new ArgumentNullException(nameof(input));
((INotifyPropertyChanged)_input).PropertyChanged += OnInputPropertyChanged;
}
public bool IsActive => !_input.Value;
private void OnInputPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(IDigitalInput.Value))
NotifyOfPropertyChange(nameof(IsActive));
}
}
Register an instance of the state message once.
var fuseIsTrippedMessage = new FuseIsTrippedStateMessage(_fuseIsOkInput);
MessageService.Instance.AddStateMessage(fuseIsTrippedMessage);
Properties
IsActive
Gets a value indicating whether the message is active.
bool IsActive { get; }
Property Value
Remarks
Active (IsActive=true) means something happened and the message should be shown. Try to avoid setting the property from outside.