【问题标题】:How to know Back Button exist on Windows Devices - Hardware/Software - Windows 10 Desktop/Mobile App - C#如何知道 Windows 设备上存在后退按钮 - 硬件/软件 - Windows 10 桌面/移动应用程序 - C#
【发布时间】:2015-10-07 14:18:16
【问题描述】:

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

有人可以帮助我吗? 谢谢

【问题讨论】:

  • 您想知道是否有硬件/系统提供了一个,还是要强制系统为您绘制一个?你最终想要做什么?

标签: c# windows-10 back uwp windows-10-mobile


【解决方案1】:

对于硬件返回按钮,您可以使用 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
    }

【讨论】:

  • 对。谢谢。但是对于虚拟后退按钮,键入以平板电脑模式运行 Windows 10,有什么建议吗?谢谢
【解决方案2】:

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

至于桌面/笔记本电脑软件按钮在应用程序的标题栏中可以启用/禁用。你可以通过获取属性AppViewBackButtonVisibility来检查它是否可见:

bool isSoftwareButton = SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility == AppViewBackButtonVisibility.Visible;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 2014-08-13
    • 2015-04-20
    • 2021-11-21
    • 1970-01-01
    • 2012-05-13
    • 2016-10-05
    相关资源
    最近更新 更多