2017-05-31 64 views
0

标题说明了它本身。对于VB,关键字NothingFalse相同。WPF/VB如何设置一个三态复选框(或可空布尔值)为Nothing(null)

此代码验证复选框是否为三态复选框,并且设置默认值indeterminate如果是“三态”,则为false,如果不是。

myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState, Nothing, False) 

的结果是一样的,总是False。我如何设置indeterminate状态?

回答

1

New Nullable(Of Boolean)怎么样?

myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState, New Nullable(Of Boolean), False) 

或更短只是New Boolean?

myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState, New Boolean?, False) 
+1

是的!它的工作原理,同时我找到了另一个解决方案,我把它作为一个替代方案写成'myThreeStateChkbox.IsChecked = If(myThreeStateChkbox.IsThreeState,DirectCast(Nothing,Boolean?),False)' – Baro

相关问题