如何在List<>的任何项目时更新视图模型属性更新了?

时间:2012-04-23 17:44:59

标签: wpf binding viewmodel

我有一个域名模型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域模型的viewmodel并添加了一个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"); }
    }
}

我有一个usercontrol border,我想绑定到ViperViewModel的InAlarm属性(闪烁红色)。但是,如果任何InstanceViper.Gauge的ShowAlarm属性为true,我需要ViperViewModel.InAlarm属性为true。当应用程序从外部源接收数据时,会更新该规范属性。当其中一个基础域模型的gauge.ShowAlarm属性设置为true时,如何/应该更新viewmodel的InAlarm属性?

1 个答案:

答案 0 :(得分:0)

EventHandler<AlarmedEventArgs>中创建event Gauge,在ShowAlarm更改时提出。

使用AlarmedEventArgs属性创建public bool?

订阅ViperViewModel中的活动,该方法应在触发时设置InAlarm