Reputation: 1092
I have used the WP7 DataBound app template for my program which utilises a form of MVVM. I would like to navigate from my mainpage to my settings page but since it is the VM that loads the data, which in turn determines if the settings pages needs to be loaded, I should like to call navigate code from the VM, not the view. However, NavigationService does not show the Navigate method in the VM, only in the view. Does anyone have any suggesions about how I can/should call the Navigate method in the VM?
Thanks,
Jason.
Upvotes: 0
Views: 611
Reputation: 26347
Implement it as a static method in your App.xaml.cs
, like this
public static void Navigate(Uri source)
{
Dispatcher.BeginInvoke(() => (App.Current.RootVisual as PhoneApplicationFrame).Navigate(source));
}
That way you can simply call App.Navigate(uri)
from anywhere.
You might also want to implement GoBack()
:
public static void GoBack()
{
Dispatcher.BeginInvoke(() => (App.Current.RootVisual as PhoneApplicationFrame).GoBack());
}
Upvotes: 1
Reputation: 52280
i tend to use one of the following
Upvotes: 1