仅在Windows 10(桌面)中显示文本框

问题描述:

我只想在Windows 10(桌面)中显示文本框,但不希望Windows 10 Mobile中出现相同的文本框。这是可能的?仅在Windows 10(桌面)中显示文本框

+7

可能的复制[检查Windows 10通用应用平台](http://stackoverflow.com/questions/32404755/check-platform-on-windows-10-universal-app) – Reniuz

+0

还需要更多信息。 –

我建议检查操作系统检测特定的功能。 Windows.Foundation.Metadata.ApiInformation是您的最佳选择。

但是如果你只关心它是否是手机的外观的东西只有一个电话就会有...这是未经测试,但你可以做这样的事情:

bool isHardwareButtonsAPIPresent = 
    Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"); 

if (isHardwareButtonsAPIPresent) 
{ 
    // The true 
} 
+0

但是,我如何将这与我希望文本框仅出现在Windows 10(桌面)而不是Windows 10 Mobile中的事实相关?这种“连接”是我无法做到的。 –

+0

将文本框的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

+0

但是,我如何将这与我希望文本框仅出现在Windows 10(桌面)而不是Windows 10 Mobile中的事实相关?这种“连接”是我无法做到的。 –

+0

@FernandoSousaa我更新了我的答案。 – AVK