Reputation: 2411
There is any way of subscribing to any field changed in ReactiveList
?
Lets say I have class:
public class A
{
public SomeOtherClass Prop1 { get; set; }
public SomeOtherClass Prop2 { get; set; }
}
And ViewModel
:
public class MyViewModel
{
private ReactiveList<A> elements;
public MyViewModel()
{
elements = new ReactiveList<A>();
}
}
This list is binded to DataGrid
. What I want to do is something like WhenAnyValue
but when Prop1
or Prop2
are changed in any A in elements
.
Is there any way?
Upvotes: 0
Views: 1651
Reputation: 169150
If you set the ChangeTrackingEnabled
property of the ReactiveList<T>
to true and raise the PropertyChanged
event in the setters of the Prop1
and Prop2
properties you can subscribe to ItemChanged
of the ReactiveList<T>
:
public MyViewModel()
{
elements = new ReactiveList<A>() { ChangeTrackingEnabled = true };
elements.ItemChanged.Subscribe(args =>
{
A a = args.Sender;
string changedProperty = args.PropertyName;
});
}
Note that the A
class must implement the INotifyPropertyChanged
interface.
Upvotes: 4