Clear Back Stack Navigation Windows 10

2020-08-26 03:54发布

I want to Clear my Navigation Back Stack History ...

I tried to use this.NavigationService.RemoveBackEntry(); but It didn't work.

How could I do this in Windows 10?

2条回答
祖国的老花朵
2楼-- · 2020-08-26 04:22

If you're in page code behind, have you tried doing:

this.Frame.BackStack.Clear();

or if you're somewhere else (like a ViewModel), have you tried:

var frame = Window.Current.Content as Frame;
frame.BackStack.Clear();
查看更多
仙女界的扛把子
3楼-- · 2020-08-26 04:40

In the code behind, you can try this:

protected override void OnNavigatedFrom(NavigationEventArgs e){
  if (this.GetType().HasRegionAttribute()){
        base.PopFromBackStackTo(typeof(LastViewModel));
  }    
  base.OnNavigatedFrom(e);
}
查看更多
登录 后发表回答