c# - 有没有一种方法可以使用 Reactive UI 订阅所有分层属性更改?

标签 c# wpf reactiveui

引用问题:( Is there a pattern for subscribing to hierarchical property changes with Reactive UI? )

我目前在我的父 react 对象中有一个子 react 对象。

public class Child : ReactiveObject
{
 private string propertyX
 public string PropertyX
    {
        get { return this.propertyX; }
        set { this.RaiseAndSetIfChanged(x => x.PropertyX, ref this.propertyX, value); }
    }

 private string propertyY
 public string PropertyY
    {
        get { return this.propertyY; }
        set { this.RaiseAndSetIfChanged(x => x.PropertyY, ref this.propertyY, value); }
    }
}

public class Parent: ReactiveObject
{

 public Parent(Child child)
 {
   Child = child;
   this.WhenAny(x => x.Child.PropertyX, x => x.Value).Subscribe(x => raisePropertyChanged("Child"));
 }

 private Child child
 public Child Child
    {
        get { return this.child; }
        set { this.RaiseAndSetIfChanged(x => x.Child, ref this.child, value); }
    }
}

我的问题是我必须写:

this.WhenAny(x => x.Child.PropertyX, x => x.Value).Subscribe(x => raisePropertyChanged("Child"));

每个子属性?

我需要这样做的原因是因为我的 DevExpress 网格不会因为嵌套属性绑定(bind)而更新。

<dxg:GridColumn x:Key="PropertyX" Header="PropertyX" FieldName="Child.PropertyX" />

最佳答案

所以,这有点 hack,但您始终可以“转发”属性:

this.WhenAny(x => x.Child.PropertyX, x => x.Value).ToProperty(this, x => x.PropertyXFromChild, out propertyXFromChild);

关于c# - 有没有一种方法可以使用 Reactive UI 订阅所有分层属性更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18020407/

相关文章:

c# - 从 C# .NET 控制台应用程序中显示图形?

c# - 如何使用 NAudio C# 更改播放速度

javascript - 在 MVC 项目中使用 JavaScript 调用 Controller 函数

wpf - Mahapps 弹出窗口未与 caliburn.micro 一起出现

c# - 来自 TreeView 控件的绑定(bind)错误

c# - ReactiveUI 的 BindTo 和 ToProperty 方法有什么区别?

C# Interactive Console.Readkey() 挂起

c# - 通过后台代码设置DataGridTextColumn.ElementStyle

silverlight - 找不到 async 修饰符所需的所有类型

c# - WPF - ReactiveUI InvokeCommand 不工作