【问题标题】:Windows Phone 8.1 Page NavigationWindows Phone 8.1 页面导航
【发布时间】:2014-04-24 03:58:05
【问题描述】:

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

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

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

Frame.Navigate(typeof(SecondPage));

【问题讨论】:

  • 嗯,不确定它是否会有所帮助,但该错误通常意味着“框架”不是您的 Page 实例的一部分。
  • @ShalinVed 是的......错误是这样的......所以我应该怎么做才能防止错误发生?
  • 你可以试试.. Frame rootFrame = Window.Current.Content as Frame rootFrame.Navigate(typeof(SecondPage));

标签: c# xaml windows-phone windows-phone-8.1


【解决方案1】:

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

如果是Windows Phone 8.1 Silverlight,那么你应该使用NavigationService.Navigate() method:

适用于:Windows Phone 8 和 Windows Phone Silverlight 8.1 | Windows Phone 操作系统 7.1

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

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

【讨论】:

  • 是的...感谢您的信息,页面重定向现在没有问题 =)
  • 我可以知道Windows Phone 8.1 运行时应用程序和silverlight 之间有什么区别吗??
  • 有不同种类的模型。 Windows Runtime apps 可以是通用应用程序(不仅适用于手机),您还会发现一些仅适用于 WinRT 的方法。 8.1 Silverlight 遵循 WP8.0,您可以在旧代码中添加新功能,而无需对代码进行重大修改。
【解决方案2】:

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

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

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

【讨论】:

    【解决方案3】:

    我使用我创建的这个小导航服务类来允许我在我的 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();
        }
    
        /// <summary>
        /// Virtual method used by the <see cref="GoBackCommand"/> property
        /// to invoke the <see cref="Windows.UI.Xaml.Controls.Frame.GoBack"/> method.
        /// </summary>
        public virtual void GoBack()
        {
            if (this.Frame != null && this.Frame.CanGoBack) this.Frame.GoBack();
        }
    
        /// <summary>
        /// Virtual method used by the <see cref="GoBackCommand"/> property
        /// to determine if the <see cref="Frame"/> can go back.
        /// </summary>
        /// <returns>
        /// true if the <see cref="Frame"/> has at least one entry 
        /// in the back navigation history.
        /// </returns>
        public virtual bool CanGoBack()
        {
            return this.Frame != null && this.Frame.CanGoBack;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多