selected checkbox in wpf
am hav开发者_JAVA技巧ing a set of checkbox in a stackpanel, i want to get the selected checkbox in my code..
how i can get those selected checkbox in a stackpanel
You can query the children of the stackpanel.
IEnumerable<CheckBox> selectedBoxes =
from checkbox in this.stackPanel1.Children.OfType<CheckBox>()
where checkbox.IsChecked.Value
select checkbox;
foreach (CheckBox box in selectedBoxes)
{
// do something
}
Same query in lambda form
IEnumerable<CheckBox> selectedBoxes =
this.stackPanel1.Children.OfType<CheckBox>()
.Where(cb => cb.IsChecked.Value);
精彩评论