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

WPF/VB How to set a threestate checkbox (or nullable boolean) to Nothing(null)

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

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

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

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

New Nullable(Of Boolean)呢?

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

或更短 New Boolean?:

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