Click here to Skip to main content
11,920,377 members (57,914 online)
Rate this:
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 9:11am
Edited 13-Sep-11 9: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 13-Sep-11 14:26pm
steersteer 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 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 415
1 phil.o 170
2 Dave Kreskowiak 155
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,495
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,805
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web01 | 2.8.151120.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