Windows 10 UAP后退按钮 [英] Windows 10 UAP back button

查看:41
本文介绍了Windows 10 UAP后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何处理Windows Mobile 10的后退按钮和Windows 10平板电脑模式的后退按钮?我到处都是,但找不到任何示例.

How would I handle the back button for windows mobile 10 and the back button for windows 10 tablet mode? I've been looking everywhere but can't find any examples for it.

推荐答案

本主题是

This topic is one of the examples used in the Guide to Universal Windows Platform apps . I strongly suggest reading that when getting started with Universal apps.

对于页面标题上的按钮,请使用Windows.UI.Core.SystemNavigationManager并将AppViewBackButtonVisibility属性设置为显示或隐藏按钮,并处理BackRequested事件以执行导航.

For the button on the page header use Windows.UI.Core.SystemNavigationManager and set the AppViewBackButtonVisibility property to show or hide the button and handle the BackRequested event to perform the navigation.

Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s,a) =>
{
    Debug.WriteLine("BackRequested");
    if (Frame.CanGoBack)
    {
        Frame.GoBack();
        a.Handled = true;
    }
}

您可以像在Windows Phone 8.1中一样连接硬件后退按钮,但是您应该检查PhoneContract(或单个类和方法)以确保它在那里:

You wire up the hardware back button the same as you do in Windows Phone 8.1, but you should check for the PhoneContract (or the individual class and method) to make sure it is there:

if (ApiInformation.IsApiContractPresent ("Windows.Phone.PhoneContract", 1, 0)) {  
    Windows.Phone.UI.Input.HardwareButtons.BackPressed += (s, a) =>
    {
        Debug.WriteLine("BackPressed");
        if (Frame.CanGoBack)
        {
            Frame.GoBack();
            a.Handled = true;
        }
    };
}

这篇关于Windows 10 UAP后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆