How do I add a 'checked'/'unchecked' event handler to a checkbox in codebehind using Silverlight?
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 Thic开发者_开发百科kness(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
}
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;
cb.Checked += CheckHandler;
精彩评论