0
我目前正在爲Windows 10開發一個應用程序。我想在我的應用程序上實現後退按鈕事件。當我按下Frame1上的後退按鈕時,應用程序關閉,正如我想要的那樣。當我在Frame2上,並導航到Frame3,然後按下後退按鈕時,應用程序自行關閉。BackButton事件關閉應用程序Windows 10應用程序
我想要的是Frame3上的後退按鈕事件使Frame3返回到Frame2,當我按下Frame2上的後退按鈕時,終止應用程序。
在我App.xaml.cs
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
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(Frame1), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
在我Frame1.xaml.cs:
private void 1_BackRequested(object sender, Windows.UI.Core.BackRequestedEventArgs e)
{
Frame frame1 = Window.Current.Content as Frame;
if (frame1 != null)
{
e.Handled = true;
Application.Current.Exit();
}
}
在我Frame2.xaml.cs:
private void 2_BackRequested(object sender, Windows.UI.Core.BackRequestedEventArgs e)
{
Frame frame2= Window.Current.Content as Frame;
if (frame2 != null)
{
e.Handled = true;
Application.Current.Exit();
}
}
在我Frame3.xaml.cs:
private void 3_BackRequested(object sender, Windows.UI.Core.BackRequestedEventArgs e)
{
Frame frame3= Window.Current.Content as Frame;
if (frame3.CanGoBack)
{
e.Handled = true;
frame3.GoBack();
}
}
你知道@JuniperPhoton是什麼嗎?謝謝你^^工作 – rydev