开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜