【问题标题】:How to determine whether XAML CheckBox is checked in C++/CX?如何确定在 C++/CX 中是否选中了 XAML CheckBox?
【发布时间】:2020-05-28 11:59:35
【问题描述】:

我的 XAML 代码:

<CheckBox x:Name="IncludeTextures" Content="Include textures"/>

C++/CX:

if (IncludeTextures->IsChecked) { // always true (even if Checkbox was not checked)

}

问题在于 IsChecked 属性始终为真。

【问题讨论】:

    标签: xaml uwp c++-cx


    【解决方案1】:

    您可以通过“值”属性获取状态(真/假)。 ...但是,当 CheckBox 处于“不确定”状态时,IsChecked 属性可以为 NULL。所以最好先完成空检查。

    if ((IncludeTextures->IsChecked != nullptr) && (IncludeTextures->IsChecked->Value))
    {
    
    }
    

    【讨论】:

      【解决方案2】:

      Equals() 方法有效:

      if (IncludeTextures->IsChecked->Equals(true)) {
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-05
        • 2020-02-21
        • 2011-06-12
        • 2013-07-03
        • 2020-09-13
        • 2020-02-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多