Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to subscribe to all hierachical property changes with Reactive UI?

Tags:

c#

wpf

reactiveui

Referring to question: (Is there a pattern for subscribing to hierarchical property changes with Reactive UI?)

I currently have a child reactiveobject in my parent reactiveobject.

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); }
    }
}

My question is that do I have to write:

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

for each child property?

The reason I need to do this is because my DevExpress grid will not update because of the nested property binding.

<dxg:GridColumn x:Key="PropertyX" Header="PropertyX" FieldName="Child.PropertyX" />
like image 325
JugheadNY Avatar asked Nov 13 '22 00:11

JugheadNY


1 Answers

So, it's a bit of a hack, but you can always "forward" a property:

this.WhenAny(x => x.Child.PropertyX, x => x.Value).ToProperty(this, x => x.PropertyXFromChild, out propertyXFromChild);
like image 141
Ana Betts Avatar answered Nov 15 '22 00:11

Ana Betts