开发者

selected checkbox in wpf

开发者 https://www.devze.com 2022-12-24 17:19 出处:网络
am hav开发者_JAVA技巧ing a set of checkbox in a stackpanel, i want to get the selected checkbox in my code..

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

精彩评论

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

关注公众号