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());
                        }
                    }
                }
            }

  • 相关阅读:
    Arduino-原理图标识
    python-垃圾回收机制
    利用浮力测密度
    sys模块-与python解释器交互的模块
    第十一章第二节 功率
    第十一章第一节 功
    类-描述器-把类对象方法转变为属性方式
    H5浏览器播放RTMP直播流
    如何查看某个端口被谁占用
    OBS第三方推流直播教程
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/2407313.html
Copyright © 2011-2022 走看看