Checked
is an event. You need to use the IsChecked
property like this...
string myString = checkBox1.IsChecked ? "It's checked" : "Not checked";
Question
New to C# and visual studio. When testing this line:
string myString = (checkBox1.Checked) ? "It's checked" : "Not checked";
I get the following error.
Error 1 The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -=
This is when playing with a WPF application. I was following a video tutorial and in their demo it worked perfectly. They might have been using windows forms.
Edit:
string myString = (checkBox1.isChecked) ? "It's checked" : "Not checked";
throws this error
Error 1 'System.Windows.Controls.CheckBox' does not contain a definition for 'isChecked' and no extension method 'isChecked' accepting a first argument of type 'System.Windows.Controls.CheckBox' could be found (are you missing a using directive or an assembly reference?)
or this error
Error 1 Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
OTHER TIPS
You want to use ToggleButton.IsChecked : http://msdn.microsoft.com/fr-fr/library/system.windows.controls.primitives.togglebutton.ischecked(v=VS.95).aspx
ToggleButton.Checked is an event, not a boolean: http://msdn.microsoft.com/fr-fr/library/system.windows.controls.primitives.togglebutton.checked(v=vs.95).aspx