A couple of days ago I asked this question, but tbh the answers have confused me even more. So I'll ask a simpler question:
(I'm using Caliburn.Micro, this is a WPF app). Suppose you have a MainView/MainViewModel which has as children AView/AViewModel and BView/BViewModel. Your MainView is a grid, and one of the cells you want to populate with either AView or BView, depending on user choices. If I only wanted to show AView, I'd do the following:
In MainView:
<StackPanel Name="SP_Controls" VerticalAlignment="Bottom" Grid.Row="1" Grid.Column="0">
<ContentControl Name="ViewModelToShow" Margin="10" />
</StackPanel>
and in the MainViewModel:
public AViewModel ViewModelToShow{get; set;}
My naive Idea now would be to do something like this:
private AViewModel _AVM;
private BViewModel _BVM;
public ... ViewModelToShow{ get; set;}
and then in the code, e.g., set the viewmodel to show:
ViewModelToShow = _BVM;
My only problem are the "...", since each ViewModel is of a different class. Is there a way to do this with generics, or should I define a base class for my ViewModels to which I cast them? But if I do that, will they still be displayed properly. Thanks.