What's the bare minimum to get a View and its associated ViewModel work together?
How can ReactiveUI handle when a View is composed of subviews (that can relate to its parent with a cardinality of 1x1 or 1xN)? Like a View with 2 SubViews and each SubView having lists of ViewModels.
According to the docs:
That's what I usually do. All your Viewmodels/SubViewmodels etc. just have a corresponding View that implements
IViewFor<whateverViewModel>. I use WPF, and this just means I have to plop in one boiler-plateViewModeldependency property and it is good to go. Then you register with ReactiveUI's IoC container, Splat:So basically whenever your View hosts a/many
ViewModelViewHostcontrol(s) on it, once you set or bind a viewmodel to it, it will look up and load the registered view.ViewModelViewHostis a container control that hosts a View.The Views are aware of the ViewModels, but the ViewModels are not aware of the Views.
As far as hierarchy goes,
ViewModelViewHostwill update based on whatever ViewModel is bound to it, and they will turtle all the way down. Usually my top-level Views are almost all a bunch ofViewModelViewHostcontrols and they just drill-down from there. Using ReactiveUI's.WhenAny()methods, you can watch properties up and down the ViewModels/SubViewModels etc. hierarchy easily and without having to worry about resubscription or null-checks.