WPF/VB 如何将三态复选框(或可为空布尔值)设置为 Nothing(null)

问题描述 投票:0回答:1

标题本身就说明了一切。对于 VB,关键字

Nothing
False
相同。

此代码验证复选框是否为三态复选框,并设置默认值,

indeterminate
如果是“三态”,则为 false。

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

结果是一样的,总是

False
。如何设置
indeterminate
状态?

wpf vb.net checkbox threestate
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.