Go to first page in C# WPF

后端 未结 3 1129
迷失自我
迷失自我 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: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.

提交回复
热议问题