Reputation: 395
I am using Visual Studio Express 2012 for Windows Phone and building an app targeting Windows Phone 7.1.
I am trying to use NavigationService to navigate to a different page but I keep running into problems.
Here is my code:
private void GotoDetails(object _url)
{
var url = string.Format("/DetailsPage.xaml?url={0}", _url.ToString());
NavigationService nav = new NavigationService();
nav.Navigate(new Uri(url, UriKind.Relative));
}
when I try to build this I get a "The type 'System.Windows.Navigation.NavigationService' has no constructors defined" on the NavigationService nav =.... line.
If I try to do just NavigationService.Navigate(new Uri(url, UriKind.Relative)); then I get a "An object reference is required for the non-static field, method, or property 'System.Windows.Navigation.NavigationService.Navigate(System.Uri)'" error.
update: I am trying to use MVVM (for the first time). This code resides in my view model. I am not using any frameworks. Just trying to learn it from scratch.
I have searched the intertubes but cannot seem to find a solution.
Any help is much appreciated.
Kamal
Upvotes: 0
Views: 1204
Reputation: 1966
are you inside a page? NavigationService is a property of the Page class: http://msdn.microsoft.com/en-us/library/system.windows.controls.page.navigationservice(v=vs.92).aspx
Upvotes: 2