-2

I'm planning wpf MVVM application. I read a lot of about MVVM pattern. But I can't find best practices to implement navigation.

I have scenario application starts with login screen and after login i want to have page with navigation menu. How should I handle that?

I read about use Frame, UserControl and viewModel container. But It's not clear to me what should I use.

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49

1 Answers1

1

Well there are 100000 options how to implement navigation

Create DataTemplates in your resources

<DataTemplate DataType="{x:Type local:YOUR_PAGE_VIEWMODEL1}">
   <local:YOUR_PAGE1/>
</DataTemplate>

<DataTemplate DataType="{x:Type local:YOUR_PAGE_VIEWMODEL2}">
   <local:YOUR_PAGE2/>
</DataTemplate>

NOTE: YOUR_PAGE_VIEWMODEL1 and YOUR_PAGE_VIEWMODEL2 have the same base class in our case (lets call it BasePageViewModel)

then in your MainViewModel you can add something like this

class MainViewModel : INotifyPropertyChanged
{
  //....
  public BasePageViewModel CurrentPage { get; set; } //don't forget to notify
  //....
}

And finaly you can bind your CurrentPage to your Frame

<Frame Content="{Binding CurrentPage}"/>
Zer0
  • 1,146
  • 6
  • 15