This project is read-only.

Navigate from View Model

Dec 5, 2013 at 9:58 PM
Hey guys,

I have a view where upon pressing the submit button the view model inserts a row into the database.

As soon as the row is done inserting the requirement is to navigate to a different page.

The usual navigation code does not work because the view model does not have access to a FrameworkElement object
DefaultLinkNavigator dln = new DefaultLinkNavigator();
dln.Navigate(new Uri("/Pages/Synchronize.xaml", UriKind.Relative), this);
Any suggestions on how to do this easily without breaking MVVM best practices?
Dec 6, 2013 at 4:30 AM
Edited Dec 6, 2013 at 4:38 AM
You should have your button wired up to a command, so when the action method for that command is invoked in your viewmodel, you can grab the MUI Navigation commands, and goto the relevant page.

Hope this helps you.

Regards
PrakashZa
Dec 6, 2013 at 1:47 PM
Edited Dec 6, 2013 at 1:47 PM
Thank you Prakashza,

do you have a code sample I could look at?

I tried the following but they give errors saying cannot find the modern frame
DefaultLinkNavigator dln = new DefaultLinkNavigator();
dln.Navigate(new Uri("/Pages/Synchronize.xaml", UriKind.Relative), Application.Current.MainWindow);

NavigationCommands.GoToPage.Execute(new Uri("/Pages/Synchronize.xaml", UriKind.Relative), Application.Current.MainWindow);
Dec 6, 2013 at 2:36 PM
I just ended up using gstarbuck's method from the discussion @ https://mui.codeplex.com/discussions/443139