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

  • 相关阅读:
    [原]音视频播放笔记
    [原]很多时候, 错误源于自己
    [原]找工作之tj
    [原]昨天碰到的一个诡异问题
    [原]硬盘分区规划
    [原]编程手记2008.08.26
    [原]编程手记2008.08.28
    eclipse 某些java文件乱码
    图片垂直居中,兼容ie6
    ul里不能直接嵌套div
  • 原文地址:https://www.cnblogs.com/KimhillZhang/p/2407313.html
Copyright © 2020-2023  润新知