views:

34

answers:

2

Okay this one's pretty straightforward. I'm creating a checkbox in my Page.xaml.cs file, and assigning it some params. I need to link to events for checked and unchecked. What is the syntax for this?

Also, my current code looks like this:

        CheckBox cb = new CheckBox();
        cb.IsChecked = true;
        System.Windows.Thickness t1 = new Thickness(425,10,0,0);
        cb.Margin = t1;
        cb.Content = "Checkbox1";

I tried adding my function to cb.Checked but it gives me the following error: "The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -="

CheckHandler is defined separately

public void CheckHandler(Object obj, EventArgs e)
{
       // Random stuff here
}
+6  A: 

You don't show the syntax you were using that resulted in the error. Am I correct in assuming it was this:

cb.Checked = CheckHandler;?

Because you wire up an event handler in C# like this:

cb.Checked += CheckHandler;

djacobson
Yes, your assumption is correct, and thanks for your answer. This works as expected now :)
Freakishly
If it works as expected mark it as right answer :)
Samvel Siradeghyan
+2  A: 
cb.Checked += CheckHandler;
Gabriel McAdams