2

Given the following declaration of a CheckBox in XAML created in Visual Studio Community 2015 in C#, how can I define the state of the CheckBox to be Intermediate on creation?

<CheckBox Margin="95,121,0,807" IsThreeState="True" IsChecked="True">Binary</CheckBox>

I have already sifted through the MSDN API for a few hours scanning these pages: https://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox.threestate(v=vs.110).aspx

I cannot seem to find a way to do this. Is it possible to initialize a CheckBox to the intermediate state?

3
  • 1
    you are looking at the wrong document I guess? XAML is not WinForm.
    – kennyzx
    Dec 22, 2015 at 14:18
  • 1
    have you tried setting the IsChecked property to null instead? ThreeState basically has True, False or Null... I am not sure how you would set that on the WPF side of things though...
    – MaxOvrdrv
    Dec 22, 2015 at 14:22
  • I am extremely new at C#, as in I just started teaching myself Sunday, so I guess I was a bit confused. Thanks for the clarifications!
    – smkarber
    Dec 22, 2015 at 14:26

2 Answers 2

2

To set the checkbox into an indeterminate state from XAML you need to do the following:

<CheckBox Name="checkBox1" IsThreeState="True" 
      IsChecked="{x:Null}"/>

The IsChecked property can be set to true, false or null and while you can simply use the strings "True" and "False" for the first two you have to specify null in this way.

Source

1
  • Thank you, I didn't understand that. Works perfect.
    – smkarber
    Dec 22, 2015 at 14:31
0

You can set the IsChecked to null like so:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<CheckBox IsChecked="{x:Null}" IsThreeState="True">Indeterminate?</CheckBox>
</Grid>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.