I am new to WPF and i am using WPF Model-View-ViewModel Toolkit 0.1 to get my hands on WPF.
I have a fairly simple question but i cant get my head around it.
How do i display new view from the menu item on the mainview?
This is how my code looks like:
MainView.xaml
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Command="{Binding NewPage}" Header="New Page"
InputGestureText="Ctrl-N" />
</MenuItem>
</Menu>
MainViewModel.cs
private DelegateCommand newPageCommand;
public ICommand NewPage
{
get
{
if (newPageCommand == null)
{
newPageCommand = new DelegateCommand(GoToNewPage);
}
return newPageCommand;
}
}
private void GoToNewPage()
{
???
}
What do i write in the GoToNewPage to display the newPage.xaml?
Usually your application is run entirely in the ViewModels, and Views are used to allow users to interact with the ViewModels in a friendly manner.
In your case, the ViewModel might have a property called
CurrentPage, which is bound to aContentControl.Contentin your View. To change pages, theGoToNewPagecommand would set theCurrentPageproperty to aNewPageViewModel.This would cause the
ContentControlto realize it’s binding has changed, and in the process of updating the binding, it would realize that theContenthas changed and it needs to use a newDataTemplateto draw that content.I have a simple example of this here if you’re interested