加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 01:44:45 所属栏目:Windows 来源:网络整理
导读:在 Windows Phone 7应用程序中,我获得了一个CurrentPage,在特殊事件中,使用NavigationService导航到新页面: NavigationService.Navigate(new Uri("/NewPage.xaml",UriKind.Relative)); 现在,当用户单击NewPage时,我希望应用程序跳过CurrentPage并直接转到应
在 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读