Reputation: 243
i have a problem with the toggleSwitch from the silverlight toolkit. i need to set the isChecked from a settings class, but i dont know hot to get the bool?
type which is required for this.
can someone give me a example how to set the isChecked property from c# code?
Upvotes: 0
Views: 2383
Reputation: 1659
The "?" qualifier on the bool type is shorthand for the Nullable struct. All that means is that you can assign null to that particular variable. This often makes sense for something like a checkbox because a checkbox can have an indeterminate state (typically reflected by a "-" in the UI). In this case, the null value would reflect that indeterminate state. In code, you'd still set the IsChecked property like you would any other boolean.
toggleCheckBox.IsChecked = true; //check the checkbox
toggleCheckBox.IsChecked = false; //uncheck the checkbox
toggleCheckBox.IsChecked = null; //set the checkbox to indeterminate state
Upvotes: 5
Reputation: 69372
I haven't used the toolkit, but bool?
is the same as a normal bool
, but it can also have the value null
. So, myToggle.IsChecked = true;
should work.
Upvotes: 2