【发布时间】:2016-03-31 15:38:53
【问题描述】:
我有 3 页。 A、B 和 C 页。
情况如下:
在所有 3 个屏幕上,我正在处理一个对象 e。 G。 Car。那些 to 按钮意味着如果我单击这样的按钮,我将通过 Frame.Navigate(typeof(...), Car) 传递 Car 引用导航到页面。按下后退按钮时,我只想返回而不传递任何参数。
问题是当我按下 to C 然后 to B e。 G。 5 次,然后当从页面B 通过后退按钮导航时,它会像这样。 C -> B -> C -> B -> C -> B -> C -> B -> A.
我的问题是:有没有办法不将导航添加到后退按钮堆栈?所以它只有一种方式 C -> B -> A,或 B -> A,或 C -> B。
我的App.xaml.cs
protected override void OnLaunched(LaunchActivatedEventArgs e) {
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.Navigated += OnNavigated;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
// Register a handler for BackRequested events and set the
// visibility of the Back button
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
rootFrame.CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
private void OnNavigated(object sender, NavigationEventArgs e) {
// Each time a navigation event occurs, update the Back button's visibility
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
((Frame)sender).CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}
private void OnBackRequested(object sender, BackRequestedEventArgs e) {
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame.CanGoBack) {
e.Handled = true;
rootFrame.GoBack();
}
}
提前谢谢你。
【问题讨论】:
标签: c# win-universal-app windows-10