I have a domain model Viper. BindableObject implements all the INotifyPropertyChanged interface.
Simplified models:
public class Viper : BindableObject
{
public int CaseId { get; set; }
public string SerialNumber { get; set; }
private byte _status;
public Byte Status
{
get { return _status; }
set { SetField(ref _status, value, "Status"); }
}
private List<CasePersonnel> _personnel;
public List<CasePersonnel> Personnel
{
get { return _personnel; }
set { SetField(ref _personnel, value, "Personnel"); }
}
private List<CaseFluids> _caseFluidList;
public List<CaseFluids> CaseFluidsList
{
get { return _caseFluidList; }
set { SetField(ref _caseFluidList, value, "CaseFluidsList"); }
}
public List<Gauge> Gauges { get; set; }
}
Gauges is a list of this type:
public class Gauge : BindableObject
{
public int GaugeId { get; set; }
public int ChannelId { get; set; }
public string Units { get; set; }
public string Code { get; set; }
private double? _value;
public double? Value
{
get { return _value; }
set { SetField(ref _value, value, "Value"); }
}
private bool? _showAlarm;
public bool? ShowAlarm
{
get { return _showAlarm; }
set { SetField(ref _showAlarm, value, "ShowAlarm"); }
}
public DateTime? TimeStamp { get; set; }
public double? Minimum { get; set; }
public double? Maximum { get; set; }
}
I created a viewmodel that references the Viper domain model and adds a InAlarm property:
public class ViperViewModel : BindableObject
{
#region Constructors
public ViperViewModel(Viper viper)
{
InstanceViper = viper;
}
#endregion
public Viper InstanceViper { get; set; }
private bool _inAlarm;
public virtual bool InAlarm
{
get { return _inAlarm; }
set { SetField(ref _inAlarm, value, "InAlarm"); }
}
}
I have a usercontrol border that I want to bind to the ViperViewModel’s InAlarm property (to blink red). However, I need the ViperViewModel.InAlarm property to be true if any of the InstanceViper.Gauge’s ShowAlarm property is true. That gauge property is updated as the application receives data from external sources. How can/should I update the viewmodel’s InAlarm property when one of the underlying domain model’s gauge.ShowAlarm property gets set to true?
Create an
EventHandler<AlarmedEventArgs>eventinGaugewhich you raise whenShowAlarmis changed.Create an
AlarmedEventArgswith apublic bool?property.Subscribe to the event in
ViperViewModeland the method should setInAlarmwhen triggered.