zoukankan      html  css  js  c++  java
  • WPF获取窗体元素

    获取窗体上面所有CheckBox选中的Content值。

    xaml:

     <StackPanel>
            <CheckBox Content="a" IsChecked="True"/>
            <CheckBox Content="b"/>
            <CheckBox Content="c" IsChecked="True"/>
            <CheckBox Content="d"/>
            <CheckBox Content="e" IsChecked="True"/>
            <CheckBox Content="f"/>
            <Button Content="Show" Width="60" Click="Button_Click"></Button>
        </StackPanel>

    cs:

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                StackPanel sp = this.Content as StackPanel;
                UIElementCollection children = sp.Children;
                foreach (UIElement ui in children)
                {
                    if (ui is CheckBox)
                    {
                        CheckBox cb = ui as CheckBox;
                        if (cb.IsChecked == true)
                        {
                            MessageBox.Show(cb.Content.ToString());
                        }
                    }
                }
            }

  • 相关阅读:
    委托系列整理
    EF Lambda 多表查询
    枚举,Enum,常规使用demo记录
    自定义Window 服务
    xpath 操作XML
    MVC 自定义过滤器
    时间比对,常用细节记录
    Lock锁_线程_线程域
    break、continue和goto 三者作用介绍
    .net 学习路线感想
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/2407313.html
Copyright © 2011-2022 走看看