0

I'm using modernUI with WPF in my desktop application. I use the code below to navigate to my usercontrol (acts like a page).

NavigationCommands.GoToPage.Execute("/Pages/MyPage.xaml?Id=" + id, this);

The navigation works well but the problem is that I don't know how I can get the Id passed as parameter. How can I fetch a parameter from MyPage.xaml?

Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90
J Dev
  • 1

1 Answers1

2

I think that implementing the IContent interface can be a solution. If you want to get the Id, you should use # instead of ?.

NavigationCommands.GoToPage.Execute("/Pages/MyPage.xaml#" + id, this);

In this case MyPage.xaml.cs can be the following:

public void OnFragmentNavigation(FragmentNavigationEventArgs e)
{
   if (!string.IsNullOrEmpty(e.Fragment))
   {
      // do what you want
      // e.Fragment will be the id
   }
}

More information on GitHub.

gaborhodi
  • 164
  • 7
  • Hello, thanks for your answer. What if I want to pass an object as a parameter (DataTable, enum item, whatever...)) – J Dev Sep 28 '15 at 09:10
  • I think that [this](http://stackoverflow.com/questions/601393/how-do-i-add-a-custom-routed-command-in-wpf) could help if that is the case. – gaborhodi Sep 30 '15 at 17:13
  • @gaborhodi Hello, i have the exact same problem and i created a class called IContent like so: https://github.com/firstfloorsoftware/mui/wiki/Handle-navigation-events. i also added the implementations and the code never reaches this point. can you help me? – Kunal Feb 27 '17 at 14:45
  • I suggest you @Kunal to create a new question and provide code snippets. – gaborhodi Feb 28 '17 at 07:17