I am a newbie to WPF and while I have read lots of theory and articles, I am unable to put it all together in a working solution.
Presently, I wish to implement dynamic multiple views in a window which could be selected by the user using buttons. The target is very much like one given in the question, WPF : dynamic view/content
Can somebody please share with me a working code, of simplest implementation of the above. Just a window which contains two grids - one grid has two buttons - second grid changes background color depending on which button is clicked. From there on , I can take things further.
Thank you very much.
Use MVVM
It's a design approach. Basically you treat your
Window
as shell, and it's responsible for swapping views.To simplify this snippet, I've referenced
MvvmLight
.The
Window
containsContentControl
which dynamically displays the relevant viewEach dynamic view can communicate with the shell
Window
(using MvvmLight'sMessenger
) and tell it to change the view to something else.MainWindow.xaml
MainWindowViewModel.cs
FirstView.xaml
FirstViewModel.cs
SecondView.xaml
SecondViewModel.cs
SwitchViewMessage.cs