I am working on a an WPF MVVM application where I need to have a Main Window with just a logo and it has to show child views inside it. I don't have any controls in Main Window all the controls reside in child view for example Buttons like Next, Back, Cancel and some text blocks etc. Now If users select Next button on the child view I have to draw or load the next child view inside the Main Window. If Back button is clicked I have to go back to the previous child view. So basically I am changing the child views depending on which button is clicked. Also I am maintaining different view models for every child view. Now the problem is I am not able to figure how should I link the child views to there respective view models. This application is similar to some Installation applications where different dialogs are shown depending on the selection and the button clicked by the user.I am new to this wpf and don't want to use MVVM Light , Prism etc. Any detailed help will be greatly appreciated. Thanks in advance.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
One of the easiest ways to associate any data type with XAML controls is to use a
DataTemplate
. Therefore, you can simply add something like this into yourApplication.Resources
and as long as you do not set thex:Key
properties on theDataTemplate
s, then they will be explicitly applied by the Framework whenever it comes across instances of your view models:Then displaying the view is as simple as this:
In code behind, or your view model:
It's often handy to create a base class for your view models and then the
YourViewModelProperty
can of that type and you will be able to interchange them using the same property andContentControl
.UPDATE >>>
The general idea is that you have one
MainViewModel
class with oneBaseViewModel
property data bound to oneContentControl
inMainWindow.xaml
... the navigation controls should also be inMainWindow.xaml
and not in the views themselves. In this way, theMainViewModel
class is responsible for changing the property to the relevant view model instances when it receives navigationCommand
s from theMainWindow.xaml
.