我有一个域模型 Viper。BindableObject 实现了所有的 INotifyPropertyChanged 接口。简化模型:
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 是这种类型的列表:
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; }
}
我创建了一个引用 Viper 域模型并添加了 InAlarm 属性的视图模型:
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"); }
}
}
我有一个想要绑定到 ViperViewModel 的 InAlarm 属性的用户控件边框(闪烁红色)。但是,如果任何 InstanceViper.Gauge 的 ShowAlarm 属性为真,我需要 ViperViewModel.InAlarm 属性为真。当应用程序从外部源接收数据时,该仪表属性会更新。当底层域模型的 gauge.ShowAlarm 属性之一设置为 true 时,我如何/应该更新 viewmodel 的 InAlarm 属性?