I'm not talking about an event handler for this, but rather a simple If Statement
checking if the CheckBox
has been checked. So far I have:
if (chkRevLoop.IsChecked == true){}
But that raises the error:
Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
Is there a way to do this that I'm missing?
Answers. If you don't need to process any user clicks on the CheckBox, setting IsHitTestVisible="false" should work.
< CheckBox Content = "I cycle through 3 states" IsThreeState = "True" /> If the IsThreeState property is set to false, the user can only cycle the CheckBox through the checked and unchecked states. You can, however, still set the CheckBox to an indeterminate state using data binding or from code.
You do need to change the ControlTemplate of the CheckBox to alter the check color, but there's a fair few programs that'll grab a template for you. Snoop, ShowMeTheTemplate, StyleSnooper to name a few.
You can use null coalescing operator. This operator returns right-hand operand if the left-hand operand is null. So you can return false
when the CheckBox
is in indeterminate state (when the value of IsChecked
property is set to null):
if (chkRevLoop.IsChecked ?? false) { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With