简体   繁体   English

Windows Phone后退按钮

[英]Windows Phone back button

I need to go back to a particular page when I click on a button. 当我点击按钮时,我需要返回特定页面。 more like custom back button. 更像是自定义后退按钮。

I can go exact page, if I know what is the page is, 我可以去确切页面,如果我知道页面是什么,

private void button_click(object sender, RoutedEventArgs e)
{
    Frame.Navigate(typeof(Page1));
}

Also I can go back to the previous page by 我也可以回到上一页

if(this.Frame.CanGoBack)
{
    Frame.GoBack();
}

But how can I jump to the page before the previous page at once? 但是如何一次跳到上一页之前的页面呢?

Any record of page history? 任何页面历史记录?

You can use NavigationServices.BackStack to access on an history of your previous pages. 您可以使用NavigationServices.BackStack访问以前页面的历史记录。

But you have not specific method to go back from 2 pages at once. 但是你没有具体的方法可以一次从2页回来。 However, if you would jump to the page before the previous page you have just to called NavigationServices.GoBack() two times. 但是,如果您要跳转到上一页之前的页面, NavigationServices.GoBack()两次调用NavigationServices.GoBack()

Moreover, if you would go back to a specific page, you can know its index between backstack and make a loop with the GoBack method. 此外,如果您要返回特定页面,您可以知道它在backstack之间的索引并使用GoBack方法进行循环。

You can get all pages from BackStack as a List : 您可以从BackStack获取所有页面作为列表:

var lstAllStackPages = this.Frame.BackStack.ToList();

and make a for loop to get your specific page and navigate to it. 并创建一个for循环来获取您的特定页面并导航到它。

Thank you @CoderDennis, I figured it out. 谢谢你@CoderDennis,我想通了。 hope it will help to someone else. 希望它能帮助别人。 I wanted to move back to the Main page if I have come along the Main page, 如果我进入主页面,我想回到主页面,

foreach (PageStackEntry stack in Frame.BackStack)
{
 //check if stack contains history of the main page. (Solution name: Helloworld)
 if (stack.SourcePageType == typeof(HelloWorld.MainPage))
   {
    Frame.Navigate(stack.SourcePageType);
    break;
   }
}

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

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