All examples which I’ve seen on the Internet has two areas – one area is for buttons to change views and another area is for views which should be changed by that buttons. So it works until you try to access commands located in the "grand-parent" data-context. However, I would like to change an entire view to another view without dividing areas or any side bar and sending data from View1 to View2, then updating View1.
I am trying to change Views in an MVVM application. For example, I have “ApplicationView” ( a host which contains DataTemplates of Views1(UserControl1) and View2(UserControl2)). These user controls have its own datacontext. xaml Of ApplicationView is:
<Window ……..>
<Window.Resources>
<DataTemplate DataType="{x:Type localViewModel:VMMain}">
<localView:MainView/>
</DataTemplate>
<DataTemplate DataType="{x:Type localViewModel:VMEditStudent}">
<localView:EditStudentView/>
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Content="{Binding CurrentPageViewModel}"/>
</Grid>
View 1(UserControl1) has own DataContext:
And View 2(UserControl2) has own DataContext too:
What I want is select an item(Adam ) in the DataGrid, click a button “Edit”, then View1 should be replaced by View 2 with filled data from a datagrid. As I understand I should change View1 by handling command of button “Edit”, and then View 2 should be displayed, then I change data and then View1 should be updated. How to do it?
Some examples with code will be greatly appreciated! Thanks.