【问题标题】:Display a text box only in Windows 10 (desktop)仅在 Windows 10(桌面)中显示文本框
【发布时间】:2017-07-18 02:53:04
【问题描述】:

我只想在 Windows 10(桌面)中显示一个文本框,我不希望在 Windows 10 移动版中出现相同的文本框。有可能吗?

【问题讨论】:

标签: c# visual-studio-2015 uwp uwp-xaml


【解决方案1】:

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

但是,如果您只关心它是否是手机,请寻找只有手机才有的东西...这是未经测试的,但您可以这样做:

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

if (isHardwareButtonsAPIPresent)
{
    // The true
}

【讨论】:

  • 但是我如何将此与我希望文本框仅出现在 Windows 10(桌面)中而不出现在 Windows 10 移动版中这一事实联系起来?这种“联系”是我做不到的。
  • 将文本框的 Visible 属性设置为 isHardwareButtonsAPIPresent 的值。
【解决方案2】:

这是我在项目中使用的一个小方法,用于检查我的应用是在mobile还是not mobile

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 移动版中这一事实联系起来?这种“联系”是我做不到的。
猜你喜欢
  • 2019-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-08
  • 2020-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多