如何知道后退按钮存在于Windows设备-硬件/软件- Windows 10桌面/移动应用程序- c#

本文关键字:Windows 硬件 软件 10桌面 应用程序 移动 设备 何知道 按钮 存在 | 更新日期: 2023-09-27 18:16:41

我需要检查运行我的应用程序的特定Windows设备是否有后退按钮,无论是在设备的硬件上还是在软件上(Windows 10在平板电脑模式下)。

有人能帮帮我吗?由于

如何知道后退按钮存在于Windows设备-硬件/软件- Windows 10桌面/移动应用程序- c#

对于硬件后退按钮,您可以使用ApiInformation轻松检查它。IsTypePresent方法。

    public MainPage()
    {
        this.InitializeComponent();
        bool isHardwareButtonsAPIPresent =
            Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");
        if(isHardwareButtonsAPIPresent)
        {
            // add Windows Mobile extenstions for UWP
            Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
        }
    }
    private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
    {
        // hareware button pressed
    }

根据MSDN,后退按钮应该始终存在:手机,平板电脑,Surface Hub。

对于桌面/笔记本软件,应用标题栏中的按钮可以开启/关闭。你可以通过获取属性AppViewBackButtonVisibility:

来检查它是否可见
bool isSoftwareButton = SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible;