简体   繁体   English

Windows Phone 8.1页面导航

[英]Windows Phone 8.1 Page Navigation

I'm still new with the Windows Phone development. 我还是Windows Phone开发的新手。 So now I'm going to develop the Windwos Phone 8.1. 所以现在我要开发Windwos Phone 8.1。 I really no idea what's the problem with the page navigation. 我真的不知道页面导航的问题是什么。 I wrote the code like this 我写了这样的代码

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

but it shows me the error ( This page does not contain a definition for "Frame" and no extension method "Frame" accepting the first arguments ) even i put like the code of bottom also the same... 但它显示了错误( 此页面不包含“框架”的定义,并且没有扩展方法“框架”接受第一个参数 )即使我像底部的代码也一样...

Frame.Navigate(typeof(SecondPage));

The Navigation depends on the kind of your project: 导航取决于您的项目类型:

If it is Windows Phone 8.1 Silverlight then you should use NavigationService.Navigate() method : 如果它是Windows Phone 8.1 Silverlight,那么您应该使用NavigationService.Navigate()方法

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

If you are targeting Windows Phone RunTime then you should use Frame.Navigate method() : 如果您的目标是Windows Phone RunTime,那么您应该使用Frame.Navigate方法()

Minimum supported phone Windows Phone 8.1 [Windows Runtime apps only] 支持的最低手机Windows Phone 8.1 [仅限Windows运行时应用]

Frame isn't a part of a Page. 框架不是页面的一部分。 I do navigation the following way 我按照以下方式进行导航

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

you just have to pass the name of the xaml page you want to navigate to. 您只需传递要导航到的xaml页面的名称即可。

I use this little Navigation Service class I created to allow me to navigate different pages from within the ViewModel of my Windows Phone 8.1 app. 我使用我创建的这个小型导航服务类,允许我从Windows Phone 8.1应用程序的ViewModel中导航不同的页面。 FYI, INavigate is part of Windows.UI.Xaml.Controls. 仅供参考,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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM