Windows Phone 8.1页面导航

我仍然是Windows Phone开发的新手。 所以现在我要开发Windwos Phone 8.1。 我真的不知道页面导航的问题是什么。 我写了这样的代码

private void hbGo_Click(object sender, RoutedEventArgs e) { this.Frame.Navigate(typeof(SecondPage)); } 

但它显示了错误( 此页面不包含“框架”的定义,并且没有扩展方法“框架”接受第一个参数 )即使我像底部的代码也一样…

 Frame.Navigate(typeof(SecondPage)); 

导航取决于您的项目类型:

如果它是Windows Phone 8.1 Silverlight,那么您应该使用NavigationService.Navigate()方法 :

适用于:Windows Phone 8和Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

如果您的目标是Windows Phone RunTime,那么您应该使用Frame.Navigate方法() :

支持的最低手机Windows Phone 8.1 [仅限Windows运行时应用]

框架不是页面的一部分。 我按以下方式进行导航

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

您只需传递要导航到的xaml页面的名称即可。

我使用我创建的这个小型导航服务类,允许我从Windows Phone 8.1应用程序的ViewModel中导航不同的页面。 仅供参考,INavigate是Windows.UI.Xaml.Controls的一部分。

 public class NavigationService : INavigate { private Frame Frame { get { return (Frame)Window.Current.Content; } } public bool Navigate(Type sourcePageType) { return Frame.Navigate(sourcePageType); } public void Navigate(Type sourcePageType, object parameter) { Frame.Navigate(sourcePageType, parameter); } public void ClearStack() { ((Frame)Window.Current.Content).BackStack.Clear(); } ///  /// Virtual method used by the  property /// to invoke the  method. ///  public virtual void GoBack() { if (this.Frame != null && this.Frame.CanGoBack) this.Frame.GoBack(); } ///  /// Virtual method used by the  property /// to determine if the  can go back. ///  ///  /// true if the  has at least one entry /// in the back navigation history. ///  public virtual bool CanGoBack() { return this.Frame != null && this.Frame.CanGoBack; } }