以下是微软提供检测是否有设想托按钮的方法
// Note: Cache the value instead of querying it more than once.
bool isHardwareButtonsAPIPresent =
Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");
if (isHardwareButtonsAPIPresent)
{
Windows.Phone.UI.Input.HardwareButtons.CameraPressed +=
HardwareButtons_CameraPressed;
}
为项目添加 Microsoft Mobile Extension SDK for Universal App Platform 引用,仍然使用 Windows.Phone.UI.Input.HardwareButtons.BackPressed 事件处理。
只适用于手机,如果是 PC,因为电脑没有返回键,会报错,所以要注意提前做好判断检查。