Using Galasoft Mvvmtoolkit, I implemented mvvm in wpf. Now I have created 3 view and 1 ViewModel for each view. Below is my sample code.
//For Main.xaml
public MainViewModel:ViewModelBase
{
ViewModelBase CurrentView{get;set;}
public MainViewModel(){
CurrentViewModel = new InfoViewModel();
}
}
//For Info.xaml
public InfoViewModel{
//Open DetailViewMode by setting
//CurrentViewModel property to an instance of DetailViewModel
ICommand ShowDetailCommand;
public InfoViewModel(){
ShowDetailCommand = new RelayCommand(()=>{
//CurrentViewModel= new DetailViewModel();
})
}
}
//For Detail.xaml
public DetailViewModel{
}
I want to show Detail.xaml usercontrol in Main.xaml which has a ContentControl in it binded to CurrentViewModel. On load, I am loading Info.xaml in it and want to show Detail.xaml when user clicks on a button present in Info.xaml
below is the codes, which worked for me once, i haven't used any toolkit. and I haven't tested the code.
And OnClick method implemented with Command, and you can use CommandParameter to decide which viewmodel you have to set as currentviewmodel.