I've seen this done inside of an event handler directly behind the .xaml file however it doesn't seem like this would follow the MVVM pattern: MainApplication.mainFrame.Navigate(new HomePage());
. Is there a better way for handling navigation with the MVVM pattern perhaps in the ViewModel? or in the XAML?
If you are looking for showing different UserControls based on the context of your data, then just understand the following simple DataBinding and DataTemplate concept and expand on it. Imagine you got a Property called CurrentViewModel which binds to the Content of a ContentControl inside your Window
<Window ...
<ContentControl Content="{Binding CurrentViewModel}" />
</Window>
Now imagine that you got ViewModel classes ClassA and ClassB, so appropriately set the instances to CurrentViewModel and define global DataTemplates (Views) for your classes
<DataTemplate DataType="{x:Type vm:ClassA}">
<local:UserControlForA../>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ClassB}">
<local:UserControlForB../>
</DataTemplate>
Now the View is automatically controlled from ViewModel logic and WPF will take care of showing the UserControl by Datatemplate.
If you are not familiar with MVVM better use this article. http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With