Windows UWP应用程序移动后退按钮不工作
我正在使用这一记录良好的解决方案为我们的应用程序添加一个后退按钮。当应用程序初始化时,我会这样设置:Windows UWP应用程序移动后退按钮不工作,windows,uwp,Windows,Uwp,我正在使用这一记录良好的解决方案为我们的应用程序添加一个后退按钮。当应用程序初始化时,我会这样设置: Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; Windows.UI.Core.SystemNavigationManager.GetForCurrentView(
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += CreateNewKeyView_BackRequested;
private void CreateNewKeyView_BackRequested(object sender, BackRequestedEventArgs e)
{
NavigationService.Instance.GoBack();
}
“后退”按钮显示在桌面应用程序上,并按预期工作,将我们的框架导航回以前的页面
然而,在Windows Phone上,硬件按钮只是退出应用程序。我在不同的地方发现了类似这样的代码,所有这些代码都表明这应该适用于移动硬件按钮,但它根本不适用于我们 你应该在
CreateNewKeyView\u backrequest
方法中设置e.Handled=true
。你应该在CreateNewKeyView\u backrequest
方法中设置e.Handled=true
。你不知道如何为导航服务编写代码,我刚刚测试了以下代码,它在我身边起作用:
private void CreateNewKeyView\u BackRequested(对象发送方,BackRequestedEventArgs e)
{
Frame rootFrame=Window.Current.Content作为Frame;
if(rootFrame!=null)
{
if(根框架.CanGoBack)
{
e、 已处理=正确;
rootFrame.GoBack();
}
}
}
或者,对于一部手机,我们也使用特殊的API
您可以通过OnLaunched
方法判断当前使用的电话Api是否为:
<代码> >(Windows .Frase.Meta .ApDealth.IsTypePresent(“Windows .Phone .UI.输入. HardwareButtons”))
{
Windows.Phone.UI.Input.HardwareButtons.BackPressed+=OnBackPressed;
}
然后完成反压的on方法:
public void OnBackPressed(对象发送方,Windows.Phone.UI.Input.backpresseedeventargs e)
{
Frame rootFrame=Window.Current.Content作为Frame;
if(rootFrame!=null)
{
if(根框架.CanGoBack)
{
e、 已处理=正确;
rootFrame.GoBack();
}
}
}
为此,首先需要在项目中为UWP
引用添加Windows Mobile扩展 不知道如何为您的导航服务编写代码,我刚刚测试了以下代码,它在我身边工作:
private void CreateNewKeyView\u BackRequested(对象发送方,BackRequestedEventArgs e)
{
Frame rootFrame=Window.Current.Content作为Frame;
if(rootFrame!=null)
{
if(根框架.CanGoBack)
{
e、 已处理=正确;
rootFrame.GoBack();
}
}
}
或者,对于一部手机,我们也使用特殊的API
您可以通过OnLaunched
方法判断当前使用的电话Api是否为:
<代码> >(Windows .Frase.Meta .ApDealth.IsTypePresent(“Windows .Phone .UI.输入. HardwareButtons”))
{
Windows.Phone.UI.Input.HardwareButtons.BackPressed+=OnBackPressed;
}
然后完成反压的on方法:
public void OnBackPressed(对象发送方,Windows.Phone.UI.Input.backpresseedeventargs e)
{
Frame rootFrame=Window.Current.Content作为Frame;
if(rootFrame!=null)
{
if(根框架.CanGoBack)
{
e、 已处理=正确;
rootFrame.GoBack();
}
}
}
为此,首先需要在项目中为UWP
引用添加Windows Mobile扩展 这是
private void CreateNewKeyView_BackRequested(object sender, BackRequestedEventArgs e) //event handle nya untuk backbutton
{
var frame = ((Frame)Window.Current.Content);
if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
这是
private void CreateNewKeyView_BackRequested(object sender, BackRequestedEventArgs e) //event handle nya untuk backbutton
{
var frame = ((Frame)Window.Current.Content);
if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
e.Handled=正确;陈述是关键。它阻止事件进一步向上通过响应程序链传递到退出应用程序的操作系统;陈述是关键。它会阻止事件进一步向上通过响应程序链传递到退出应用程序的操作系统。