仅在Windows 10(桌面)中显示文本框
我建议检查操作系统检测特定的功能。 Windows.Foundation.Metadata.ApiInformation是您的最佳选择。
但是如果你只关心它是否是手机的外观的东西只有一个电话就会有...这是未经测试,但你可以做这样的事情:
bool isHardwareButtonsAPIPresent =
Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");
if (isHardwareButtonsAPIPresent)
{
// The true
}
但是,我如何将这与我希望文本框仅出现在Windows 10(桌面)而不是Windows 10 Mobile中的事实相关?这种“连接”是我无法做到的。 –
将文本框的Visible属性设置为isHardwareButtonsAPIPresent的值。 –
这里是一个小方法,我用在我的项目检查,如果我的应用程序是移动或不移动
public static bool IsMobile()
{
String str = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
bool _isMobile = (str == "Windows.Mobile") ? true : false;
return _isMobile;
}
更新:如果你想在代码隐藏使用
,
textBox.Visibility = (IsMobile()) ? Visibility.Collapsed : Visibility.Visible;
如果你想通过DataBinding
使用,您可以创建一个属性,并使用相同的逻辑返回Visibility
但是,我如何将这与我希望文本框仅出现在Windows 10(桌面)而不是Windows 10 Mobile中的事实相关?这种“连接”是我无法做到的。 –
@FernandoSousaa我更新了我的答案。 – AVK
可能的复制[检查Windows 10通用应用平台](http://stackoverflow.com/questions/32404755/check-platform-on-windows-10-universal-app) – Reniuz
还需要更多信息。 –