Reputation: 158
I think I am missing a fundamental Observable concept.
I have a ChargeViewModel class which has a ReactiveList property which is a collection of itself ChargeViewModel.Charges which contains related charges
I want to observe the latest entry in the charges collection (it has a ChargeViewModel.lastModified) and also have other properties in the UI based on the latest entry.
In the ctor I have this code which works to initialize the values; however it does not update the values for latestActionDate, latestBillToName, lastestNote when the observable variable "last" changes
I want the UI to update if the user updates the "last" charge or creates a new "last".
var last = Charges?
.Changed
.Select(_ => Charges.OrderByDescending(c => c.Model.LastModified).FirstOrDefault())
.StartWith(Charges.OrderByDescending(c =>c.Model.LastModified).FirstOrDefault());
last
.Select(c => c.Model.LastModified)
.ToProperty(this, vm => vm.LatestActionDate, out latestActionDate);
last
.Select(c => c.Model.BillToName)
.ToProperty(this, vm => vm.LatestBillToName, out latestBillToName);
last
.Select(c => c.Model.Note)
.ToProperty(this, vm => vm.LatestNote, out latestNote);
Upvotes: 1
Views: 218
Reputation: 2962
ReactiveList
(by default) only notifies upon elements added/moved/removed, not upon content changes. It's fairly simply to enable it (and maybe you already did) by setting ChangeTrackingEnabled=true
.
However when enabled, you'll receive such motifications on ItemChanged
observable, and not on Changed
one, so in your case you probably need to do:
Charges.Changed.Select(_ => Unit.Default).Merge(Charges.ItemChanged.Select(_ => Unit.Default))
.Select(_ => /* ... */)
....
Upvotes: 2