导航到新页面而不将当前页面放在后台堆栈上?

Sam*_*Sam 6 navigation windows-phone-7

在Windows Phone 7应用程序中,我获得了一个CurrentPage,在特殊事件中,使用NavigationService导航到新页面:

NavigationService.Navigate(new Uri("/NewPage.xaml", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)

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

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

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

小智 11

导航到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));

的OnNavigatedTo事件NewPage.xaml,检查是否要删除以前的网页或没有.


    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.