Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Visual-Studio WPF
I was trying to implement a small piece of code for my checkbox within a method using wpf, and i got this error.
 
"
Error   1   The event;System.Windows.Controls.Primitives.ToggleButton.Checked&; can only appear on the left hand side of += or -= "
 

 
public void test()
{
 
if (checkBox1.Checked)
                   {
                      MessageBox.Show("checkbox is checked now");
                     }
else
{
MessageBox.Show("checkbox is unchecked now");
}
}
 
Any help would be much appreciated. Thanks
Posted 13-Sep-11 9:11am
Edited 13-Sep-11 9:16am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

checkBox1.Checked is the event which is generated when the state of the checkbox is changed. checkBox1.IsChecked is the state of the checkbox.
So to determine the current state of the checkbox use
if (checkBox1.IsChecked)
  Permalink  
Comments
steersteer at 13-Sep-11 14:26pm
   
Thanks
steersteer at 13-Sep-11 14:44pm
   
thanks. Could you please tell me how to uncheck the checkbox once after the messagebox is displayed ? ( i tried checkbox1.ischecked == false but that didn't work. I want the checkbox to be unchecked if it is checked and checked if it is not checked.
CIDev at 13-Sep-11 15:03pm
   
That should be checkbox1.IsChecked = false; note that there only 1 equals sign.
 
If this solution answers your question you should mark it as the answer. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 260
1 Afzaal Ahmad Zeeshan 252
2 OriginalGriff 251
3 Mathew Soji 234
4 Maciej Los 230
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 22 Nov 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100