I am implementing a typical master-details GUI pattern using WPF and ReactiveUI. I would like to keep the master viewmodel and the details viewmodel decoupled from each other without resorting to something more fragile and indirect like message bus. However something isn't working.
I have two questions:
- Why is
WhenAnyValue
not working in my code below? - What is the recommended way of implementing decoupled master-details in ReactiveUI nowadays?
Code:
public class ShellViewModel : ReactiveObject
{
public ShellViewModel(OrderListViewModel orderListViewModel, OrderDetailsViewModel orderDetailsViewModel)
{
OrderListViewModel = orderListViewModel;
OrderDetailsViewModel = orderDetailsViewModel;
this.WhenAnyValue(x => x.OrderListViewModel.SelectedOrderHeader).Do(h =>
{
OrderDetailsViewModel.Set(h);
});
}
public OrderListViewModel OrderListViewModel { get; }
public OrderDetailsViewModel OrderDetailsViewModel { get; }
}
I have omitted the two underlying viewmodels and related views because they are very typical (observable list + selected item property) and seem to be working fine by themselves.
Update: the the #1 can be "fixed" by using Subscribe
instead of Do
. I don't know what is the purpose of the latter?