如何移除's的NavigationService
本文关键字:NavigationService 何移 | 更新日期: 2023-09-27 17:49:27
我已经创建了一个带有几个页面的框架。框架有自己的日志:
JournalOwnership="OwnsJournal"
当我通过2页时,我想要清理框架NavigationService
:
Frame parent_frame = (Frame)Application.Current.MainWindow.FindName("content_frame");
JournalEntry remove = parent_frame.RemoveBackEntry();
while (parent_frame.NavigationService.CanGoBack) {
parent_frame.NavigationService.RemoveBackEntry();
MessageBox.Show("Remove");
}
但清理完NavigationService
后,我可以回去。
最简单的方法是处理frame Navigated事件:
frame.Navigated += frame_Navigated;
void frame_Navigated(object sender, NavigationEventArgs e)
{
frame.NavigationService.RemoveBackEntry();
}
我已经删除了NavigationService.BackStack
中所有可能的页面,并在删除最后一页时添加了事件。
Frame root = (Frame)Application.Current.MainWindow.FindName("content_frame");
int i = 0;
while (root.NavigationService.CanGoBack) {
i++;
root.NavigationService.RemoveBackEntry();
}
root.NavigationService.RemoveBackEntry();
MessageBox.Show("Deleted - " + i);
NavigatedEventHandler navigated_handle = null;
navigated_handle = (o, e) => {
((Frame)o).RemoveBackEntry();
MessageBox.Show("Do and remove itself!");
root.Navigated -= navigated_handle;
};
root.Navigated += navigated_handle;