【问题标题】:INotifyPropertyChanged for property of propertyINotifyPropertyChanged 用于属性的属性
【发布时间】:2011-10-25 16:20:01
【问题描述】:

我认为描述这个问题的最好方法是用一个非常简单的例子......

假设您有两个班级。打电话给他们TrainStatus

TrainDomainService 中,您有如下一行:

[Include]
public Status { get; set;}

Status 有两个属性:NameDisplayColor

  1. 现在,将Train 对象中的ObservableCollection 绑定到DataGrid
  2. StatusObservableCollection 绑定到另一个DataGrid
  3. 然后更新Status 对象之一。
  4. 有没有办法让这个变化自动反映在持有Train对象的DataGrid中?

谢谢!!!

【问题讨论】:

    标签: silverlight wcf inotifypropertychanged


    【解决方案1】:

    我认为这就是你想要的(假设服务和状态都实现了 INotifyPropertyChanged):

    private Status _status;
    
    [Include]
    public Status Status
    {
      get { return _status; }
      set 
      {
        if (_status == value) return;
    
        if (_status != null)
           _status.PropertyChanged -= NotifyStatusChanged;
    
        _status = value;
    
        // Whatever your implementation of INotifyPropertyChanged looks like.
        RaiseNotifyPropertyChanged(()=> Status);
    
        if (_status != null)
           _status.PropertyChanged += NotifyStatusChanged;
      }
    }
    
    private void NotifyStatusChanged(object o, EventArgs e) 
    {
        // Whatever your implementation of INotifyPropertyChanged looks like.
        RaiseNotifyPropertyChanged(()=> Status);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-12
      • 2021-06-25
      • 2013-08-12
      • 2019-04-04
      • 2011-04-04
      • 2013-01-14
      • 2011-03-21
      • 2011-01-15
      相关资源
      最近更新 更多