INotifyPropertyChanged 用于属性的属性

发布于 2024-12-11 14:00:20 字数 663 浏览 0 评论 0原文

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

想象一下你有两个类。称它们为TrainStatus

TrainDomainService 中,有一行如下所示:

[Include]
public Status { get; set;}

Status 有两个属性:Name 和 <代码>显示颜色。

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

谢谢!

I think the best way to describe this question is with a very simple example....

Imagine that you have two classes. Call them Train and Status.

In the DomainService for Train you have a line that looks like:

[Include]
public Status { get; set;}

The Status has two properties: Name and DisplayColor.

  1. Now, bind an ObservableCollection of Train objects to a DataGrid
  2. Bind an ObservableCollection of Status to another DataGrid.
  3. Then update one of the Status objects.
  4. Is there any way to make this change reflect automatically in the DataGrid holding the Train objects?

Thank you!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我要还你自由 2024-12-18 14:00:20

我认为这就是您想要的(假设服务和 Status 都实现 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);
}

I think this is what you want (assuming both the service and Status implement 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文