windows phone app navigation error: NavigationService does not exist in current Context

windows phone app navigation error: NavigationService does not exist in current Context

我正在开发一个小型 windows phone 应用程序。

我想从 MainPage.xaml 导航到 secondPage.xaml

NavigationService.Navigate(new Uri("SecondPage.xaml", UriKind.Relative));

但是它显示了一个错误消息,即当前上下文中不存在 NavigateService

由于您正在开发 Windows Phone XAML 应用程序,因此您需要使用页面的框架 属性 处理导航,例如

this.Frame.Navigate(typeof(SecondPage));

此外,如上所示,您需要传递 typeof(Page) 而不是 Uri

您是否尝试在页面构造函数中执行此操作?如果您将代码移动到 OnNavigateTo 应该没问题....