CheckBox Example

singlecheckbox.jpg

Here is an example of adding a single Checkbox to a StackPanel and subscribing to its "Checked" and "Unchecked" events:

CheckBox cbx = new CheckBox();
cbx.Initialize(ContainerType.HorizontalPanel, true, false);

//Add text to the CheckBox
cbx.BeginComposite<CheckBox>()
.AddText<CheckBox>(0, 0, "Water")
.EndComposite<CheckBox, CheckBoxArgs>(null);

stkPanel1.BeginSettings<StackPanel>()
.Set<CheckBox, StackPanel>(0, 1, "Margin", new Thickness(5))
.EndSettings<StackPanel>();

//Add the CheckBox to a StackPanel Parent, wiring up the Checked and Unchecked events
stkPanel1.BeginComposite()
.AddExisting<CheckBox, StackPanel>(0, 1, cbx)
.SubscribeEventOnChild<CheckBox, StackPanel, RoutedEventArgs>(0, 1, "Checked", 
((o, revargs) => { System.Windows.MessageBox.Show("Checkbox has been checked!"); }), 
chbx => { return true; })
.SubscribeEventOnChild<CheckBox, StackPanel, RoutedEventArgs>(0, 1, "Unchecked", 
((o, revargs) => { System.Windows.MessageBox.Show("Checkbox has been un-checked!"); }), 
chbx => { return true; })
.EndComposite<StackPanel, StackPanelArgs>(null);

Last edited Mar 28, 2014 at 9:08 PM by stagathome0069, version 5

Comments

No comments yet.