gpt4 book ai didi

C# 识别代码是否在 Windows Phone 或平板电脑/计算机中运行

转载 作者:行者123 更新时间:2023-11-30 23:27:44 26 4
gpt4 key购买 nike

我需要确定我的代码是在 Windows Phone 10 还是 Windows 10 上运行。已尝试使用此代码,但没有成功:

       public static Platform DetectaPlataforma()
{
bool APIBotoesPresent = ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");
if (APIBotoesPresent)
{
(App.Current as App).Telefone = true;
return Platform.WindowsPhone;
}
else
{
(App.Current as App).Telefone = false;
return Platform.Windows;
}
}

它始终检测 Windows,即使在手机上运行时也是如此。我做错了什么?

最佳答案

将此添加到

App.XAML.CS

public static bool IsMobile
{
get
{
var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
return (qualifiers.ContainsKey("DeviceFamily") && qualifiers["DeviceFamily"] == "Mobile");
}
}

关于C# 识别代码是否在 Windows Phone 或平板电脑/计算机中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com