I am adding checkboxes dynamically to silverlight stackpanel object as follows:
foreach (String userName in e.Result)
{
CheckBox ch = new CheckBox();
ch.Name = userName;
ch.Content = userName;
ContentStackPanel.Children.Add(ch);
}
How do I read back those controls to detect which of them are checked.
You should probably avoid creating checkboxes in code like this. Something that might be useful for you is a mini “ViewModel” for the checkbox. Something like this:
Then, you can have a collection of these options like this:
Once this is populated, you can bind the ObservableCollection to an ItemsControl:
That XAML will create the CheckBoxes for you for ever option you added to your options collection. The really great thing is that you can now ask you options collection which options have been selected:
Using data binding and templates is a technique you should get familiar with in Silverlight/WPF. It is a really important concept, and it will let you do amazing things in you application.