Lets say I have a MainWindow and in it one Grid Column where i place my UserControl. And the user can switch the usercontrol in this column with a button click, a tab or a menuItem.
I have 3 userControls : UserControl1, UserControl2 , USerControl3 3 ViewModels : UserControl1ViewModel, UserControl2ViewModel, UserControl3ViewModel a MainWindow and a MainWindowViewModel
Lets say that in this column the default userControl is the UserControl1. How do I switch it with a Button click to UserControl2.
I found some resources like this :
<Window.Resources>
<DataTemplate DataType="{x:Type vm:UserControl1ViewModel}">
<v:UserControl1 />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:UserControl2ViewModel}">
<v:UserControl1 />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:UserControl3ViewModel}">
<v:UserControl3/>
</DataTemplate>
</Window.Resources>
The idea is to somehow bind a Command to Button or MenuItem to switch the UserControls. That code is going to be handled in MainWindowViewModel.