I've got a View (MainView) which contains a kind of main content area (MainContent). The View is backed by a corresponding ViewModel (MainViewModel). The main content changes, of course, based on the current state of the application and is represented in the ViewModel as a property (CurrentPrimaryViewModel). The content of MainContent is bound to CurrentPrimaryViewModel in the XAML like so:
Content="{Binding Path=CurrentPrimaryViewModel}"
There's a ResourceDictionary containing a bunch of ViewModel->View mapping DataTemplates. So if the CurrentPrimaryViewModel is of type XViewModel, it resolves to XView.
This all works, kind of.
The problem is that every time the CurrentPrimaryViewModel changes a new View is created. What I'd like is for appropriately mapped View to simply have it's DataContext changed to the correct ViewModel and then have that View become the MainContent. Basically like the CardStack? layout from Java, or a TabControl without visible tabs.
What's the appropriate technique for handling this situation? Do I just have to create the various Views under the MainContent wrapper and toggle their visibility or Z-Order? Is there a good pattern for this? What should be bound between the MainView and MainViewModel in order to accomplish this?