微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

windows-phone-7 – 导航到新页面而不将当前页面放在后台堆栈上?

Windows Phone 7应用程序中,我获得了一个CurrentPage,在特殊事件中,使用NavigationService导航到新页面
NavigationService.Navigate(new Uri("/NewPage.xaml",UriKind.Relative));

现在,当用户单击NewPage时,我希望应用程序跳过CurrentPage并直接转到应用程序的MainPage.

我尝试使用NavigationService.RemoveBackEntry,但这会删除MainPage而不是CurrentPage.

如何在不将当前值放在后台堆栈的情况下导航到新页面

导航到NewPage.xaml传递参数时,您知道何时从Backstack中删除上一页.

你可以这样做:

从CurrentPage.xaml导航到NewPage.xaml时,沿参数传递


    bool remove = true;
    String removeParam = remove ? bool.TrueString : bool.FalseString;

    NavigationService.Navigate(new Uri("/NewPage.xaml?removePrevIoUs="+removeParam,UriKind.Relative));

在NewPage.xaml的OnNavigatedTo事件中,检查是否删除上一页.


    bool remove = false;

    if (NavigationContext.QueryString.ContainsKey("removePrevIoUs"))
    {
        remove = ((string)NavigationContext.QueryString["removePrevIoUs"]).Equals(bool.TrueString);
        NavigationContext.QueryString.Remove("removePrevIoUs");
    }

    if(remove)
    {
        NavigationService.RemoveBackEntry();
    }

这样,如果要从Backstack中删除它,可以决定CurrentPage.xaml.

原文地址:https://www.jb51.cc/windows/363620.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐