引用问题:( 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/