zoukankan      html  css  js  c++  java
  • CheckBox 动态操作

    <WrapPanel Orientation="Horizontal" x:Name="wplContent"/>

    添加控件

    private CheckBox GenerateCheckBox(string name, string tag = "")
    {
        var cb = new CheckBox
        {
            Margin = new Thickness(5, 5, 5, 5),
            IsChecked = false,
            Content = name,
            Tag = tag,
        };
    
        return cb;
    }
    public void AddCheckBox(string name, string tag)
    {
        var cb = GenerateCheckBox(name, tag);
        wplContent.Children.Add(cb);
    }
    

    删除控件

    public void RemoveCheckBox(string tag)
    {
        var item = wplContent.Children.OfType<CheckBox>().FirstOrDefault(x => x.Tag.ToString() == tag);
        if (item != null)
        {
            wplContent.Children.Remove(item);
        }
    }
    

    是否都没选择

    /// <summary>
    /// 是否都没选择
    /// </summary>
    /// <returns>true都没选, false至少有一个勾选</returns>
    public bool IsAllUnSelected()
    {
        var list = wplContent.Children.OfType<CheckBox>();
        return list.Any(x => x.IsChecked == true);
    }
    

    获取所有的显示内容

    /// <summary>
    /// 获取所有的显示内容
    /// </summary>
    /// <returns>形如: 1,2,3</returns>
    public string GetNames()
    {
        var list = wplContent.Children.OfType<CheckBox>();
        var arr = list.Select(s => s.Name).ToArray();
        return string.Join(",", arr);
    }
    

    设置选中

    /// <summary>
    /// 设置选中
    /// </summary>
    /// <param name="tags"></param>
    public void SetChecked(IEnumerable<string> tags)
    {
        foreach (var item in wplContent.Children.OfType<CheckBox>())
        {
            if (tags.Contains(item.Tag.ToString()))
            {
                item.IsChecked = true;
            }
            else
            {
                item.IsChecked = false;
            }
        }
    }
    
  • 相关阅读:
    rosservice call ERROR:Unable to load type ... Have you typed 'make'
    查看ubuntu版本号
    VirtualBox虚拟机 host/guest 拷贝粘贴,共享剪贴板,安装guest additions
    traffic_light_bag_file 数据集 下载链接
    ubuntu linux double tab
    ubuntu linux查看cpu信息
    ubuntu linux查看硬盘使用量
    ubuntu查看nvidia显卡状态
    ibus
    windows7 屏幕亮图胡乱变化
  • 原文地址:https://www.cnblogs.com/wesson2019-blog/p/14637481.html
Copyright © 2011-2022 走看看