Ich habe 3 Seiten. Seite A, B und C.UWP - Navigation aus dem Back-Button-Stack ausschließen
Die Situation sieht wie folgt aus:
Auf allen drei Bildschirmen Ich bin mit einem Objekt e arbeiten. G. Car
. Die Schaltflächen bis bedeuten, dass ich, wenn ich auf eine solche Schaltfläche klicke, auf die Seite Frame.Navigate(typeof(...), Car)
gehe und die Car
Referenz übergebe. Beim Zurück-Knopfdruck möchte ich einfach zurückgehen, ohne irgendwelche Parameter zu übergeben.
Das Problem ist, dass, wenn I bis C drücken und dann e auf b. G. 5 mal, dann beim Navigieren über Zurück-Taste von Seite B
geht es so. C -> B -> C -> B -> C -> B -> C -> B -> A.
Meine Frage ist: Gibt es eine Möglichkeit, die Navigation zum Back-Button-Stack nicht hinzuzufügen? So geht es nur einen Weg, C -> B -> A oder B -> A oder C -> B.
Mein 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();
}
}
Vielen Dank im Voraus.
Ich denke, es ist wenig destruktiv, da Sie nur das erste Element von 'BackStack' erhalten, bevor Sie es löschen. Wenn Sie A -> B -> C gehen, können Sie nicht C -> B aufrufen, indem Sie 'this.Frame.GoBack()' aufrufen –