Go to first page in C# WPF

后端 未结 3 1130
迷失自我
迷失自我 2020-12-20 22:35

I am using navigation services in WPF. For navigating to page I use:

this.NavigationService.Navigate(new MyPage());

For going back I use:

相关标签:
3条回答
  • 2020-12-20 23:19

    One way could be to use method RemoveBackEntry until there is only a single entry left in the back stack of navigation service. Once there is only a single entry simple do Navigation.GoBack()

    0 讨论(0)
  • 2020-12-20 23:25

    Consider implementing PageFunction<T>. This class (derived from Page) is designed for scenarios when you want to unwind to a 'start' page. It can return/provide an object of type T as a result upon 'completion' of the use case (function).

    More detail (better than msdn) can be found here http://paulstovell.com/blog/wpf-navigation

    0 讨论(0)
  • 2020-12-20 23:34

    Here's a potential solution, however there may be a 'best practice' method that i'm not currently aware of:

    while(this.NavigationService.CanGoBack)
    {
       this.NavigationService.GoBack();
    }
    

    CanGoBack returns true if there are entries in the back navigation history and as such GoBack() will be executed until it returns false. In theory this should get you back to the origin, or in other words the first page.

    0 讨论(0)
提交回复
热议问题