Click here to Skip to main content
11,804,008 members (80,052 online)
Rate this: bad
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");
MessageBox.Show("checkbox is unchecked now");

Any help would be much appreciated. Thanks
Posted 13-Sep-11 8:11am
Edited 13-Sep-11 8:16am

1 solution

Rate this: bad
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)
steersteer at 13-Sep-11 14:26pm
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 OriginalGriff 410
1 CPallini 310
2 Sergey Alexandrovich Kryukov 234
3 CHill60 230
4 Suvendu Shekhar Giri 200
0 OriginalGriff 3,140
1 Maciej Los 1,910
2 KrunalRohit 1,907
3 CPallini 1,845
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 22 Nov 2013
Copyright © CodeProject, 1999-2015
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