Click here to Skip to main content
13,097,230 members (63,086 online)
Rate this:
Please Sign up or sign in to vote.
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
Updated 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 22 Nov 2013
Copyright © CodeProject, 1999-2017
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