1

I'm using WPF ModernUI and I would like to navigate to a page and set the page DataContext as well.

To navigate I'm using the following:

NavigationCommands.GoToPage.Execute("view/pages/TaskEditPage.xaml", this);

Is there any other way to navigate to a page or is there any way to get the instance of that page so I could set the DataContext?

rbasniak
  • 4,484
  • 11
  • 51
  • 100

2 Answers2

1

Long time (and the only one) since I used ModernUI , navigation usually was something like the following:

NavigationCommands.GoToPage.Execute("view/pages/TaskEditPage.xaml#TaskID=xyz", this);

Then you can:

public void OnFragmentNavigation(FragmentNavigationEventArgs e)
{
  //e.Fragment will be "TaskID=xyz"
  RetrieveTaskFromStore(e.Fragment)
}
E-Bat
  • 4,792
  • 1
  • 33
  • 58
1

The ModernFrame control, which hosts the current page, inherits from ContentControl and so has a Content property, which is the current page.

But, using fragment navigation provides good separation of concerns. Let the view decide which view model class to use as the DataContext and use fragment navigation to help load particular data for the view model.

Glen Thomas
  • 10,190
  • 5
  • 33
  • 65