C#后台实现在Grid标签中动态新增CheckBox标签(WPF中)
- 页面代码


<Grid Margin="45,0,10,0" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Name="controlReasonGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<CheckBox Margin="10,0" Name="controlReason1" Content="北京" Style="{StaticResource CommonCheckBoxStyle}" />
<CheckBox Grid.Column="" Name="controlReason2" Content="上海" Style="{StaticResource CommonCheckBoxStyle}" />
<CheckBox Grid.Column="" Name="controlReason3" Margin="10,0,0,0" Content="深圳" Style="{StaticResource CommonCheckBoxStyle}" />
<CheckBox Grid.Column="" Name="controlReason4" Content="广州" Style="{StaticResource CommonCheckBoxStyle}"/> <TextBox Name="controlReasonTextBox" Grid.Column="" Style="{StaticResource CommonTextBoxStyle}" Height="" Margin="29,0,0,0" />
<Button Grid.Column="" Name="controlReasonButton" Content="新 增" Width="" Style="{StaticResource CommonButtonStyle}" Margin="0,0,84,0" Click="controlReasonButton_Click"/>
</Grid>
</Grid>
- 后台代码


List<CheckBox> m_AllCheckBoxs2 = new List<CheckBox>();//存放checkBox private void controlReasonButton_Click(object sender, RoutedEventArgs e)
{ if (m_AllCheckBoxs2.Count == )
{
controlReasonTextBox.Visibility = Visibility.Collapsed;
controlReasonButton.Visibility = Visibility.Collapsed;
}
if (controlReasonTextBox.Text == "")
{
MessageBox.Show("值不能为空!");
return;
}
foreach (var item in m_AllCheckBoxs2)
{
if (controlReasonTextBox.Text == item.Content.ToString())
{
MessageBox.Show("值不能相同!");
return;
}
}
AddCheckBox(""); }
private void AddCheckBox(string checkValue)
{
int prev = Convert.ToInt32(m_AllCheckBoxs2.Last().GetValue(Grid.ColumnProperty)) + ;//获取集合最后一个元素的列
if (m_AllCheckBoxs2.Count > ) return;
CheckBox checkBox = new CheckBox
{
Name = "controlReason" + (prev) + "",
Content = checkValue != "" ? checkValue : controlReasonTextBox.Text,
IsChecked = checkValue != "" ? true : false,
};
foreach (var item in m_AllCheckBoxs2)
{
if (item.Content.ToString() == checkBox.Content.ToString())
{
return;
}
}
checkBox.SetValue(CheckBox.StyleProperty, Application.Current.Resources["CommonCheckBoxStyle"]);//绑定样式
checkBox.SetValue(Grid.ColumnProperty, prev); //设置按钮所在Grid控件的列
controlReasonGrid.Children.Add(checkBox); int curr = Convert.ToInt32(checkBox.GetValue(Grid.ColumnProperty)) + ;//获取当前复选框所在列
controlReasonTextBox.SetValue(Grid.ColumnProperty, curr);//文本框 int prev2 = Convert.ToInt32(controlReasonTextBox.GetValue(Grid.ColumnProperty)) + ;//获取文本框所在列
controlReasonButton.SetValue(Grid.ColumnProperty, prev2);//新增按钮
checkBox.Checked += cb_Checked2;//绑定事件
checkBox.Unchecked += cb_Unchecked2;//绑定事件
ChangeSelAllChecked(checkBox, m_AllCheckBoxs2); m_AllCheckBoxs2.Add(checkBox);
}
C#后台实现在Grid标签中动态新增CheckBox标签(WPF中)的更多相关文章
- jquery中动态新增的元素节点无法触发事件解决办法
在使用jquery中动态新增的元素节点时会发现添加的事件是无法触发的,我们下面就为各位来详细的介绍此问题的解决办法. 比如做一个ajax读取留言列表的时候,每条留言后面有个回复按钮,class为“re ...
- es6 Object.assign ECMAScript 6 笔记(六) ECMAScript 6 笔记(一) react入门——慕课网笔记 jquery中动态新增的元素节点无法触发事件解决办法 响应式图像 弹窗细节 微信浏览器——返回操作 Float 的那些事 Flex布局 HTML5 data-* 自定义属性 参数传递的四种形式
es6 Object.assign 目录 一.基本用法 二.用途 1. 为对象添加属性 2. 为对象添加方法 3. 克隆对象 4. 合并多个对象 5. 为属性指定默认值 三.浏览器支持 ES6 O ...
- c# json转换成dynamic对象,然后在dynamic对象中动态获取指定字符串列表中的值
using Newtonsoft.Json;using System;using System.Collections.Generic;using System.Linq;using System.T ...
- Action中动态方法的调用 Action中通配符的使用 Result的配置
Action中动态方法的调用 动态方法调用(Dynamic Method Invocation,DMI) 标识符:! 一.通过以下选中的文件来查看是否禁止调用动态方法
- 【转】vue中动态设置meta标签和title标签
因为和原生的交互是需要h5这边来提供meta标签的来是来判断要不要显示分享按钮,所有就需要手动设置meta标签,标题和内容 //router内的设置 { path: '/teachers', name ...
- jquery中动态添加的标签绑定的click事件失效的解决办法
把.click()换成.live('click',function(){})(如果你的jquery的版本是1.10之前) 把.click()换成.on('click',function(){})(jq ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(17)-LinQ动态排序
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(17)-LinQ动态排序 首先修复程序中的一个BUG这个BUG在GridPager类中,把sord修改为s ...
- 某APK中使用了动态注册BroadcastReceiver,Launcher中动态加载此APK出现java.lang.SecurityException异常的解决方法
在某APK中,通过如下方法动态注册了一个BroadcastReceiver,代码参考如下: @Override protected void onAttachedToWindow() { super. ...
- 分别在javascript和JSP中动态设置下拉列表默认值
一.JavaScript中动态设置select标签中<option>选项的默认值: 比如,要完成下边这个下拉列表的动态显示,并且当进行前后翻页时,下拉列表中的值自动更新为当前页码: 图1 ...
随机推荐
- elasticsearch集群配置 (Tobe Continue)
elasticsearch集群配置 (Tobe Continue) 准备 首先需要在每个节点有可以正常启动的单节点elasticsearch elasticsearch集群配置仅需要在elas ...
- 数据可视化之powerBI基础(三)编辑交互,体验更灵活的PowerBI可视化
https://zhuanlan.zhihu.com/p/64412190 PowerBI可视化与传统图表的一大区别,就是可视化分析是动态的,通过页面上筛选.钻取.突出显示等交互功能,可以快速进行访问 ...
- 数据可视化之分析篇(四)PowerBI分析模型:产品关联度分析
https://zhuanlan.zhihu.com/p/64510355 逛超市的时候,面对货架上琳琅满目的商品,你会觉得这些商品的摆放,或者不同品类的货架分布是随机排列的吗,当然不是. 应该都听说 ...
- 轮播图-bxslider
bxSlider下载+参数说明 “bxSlider”就是一款响应式的幻灯片js插件 bxSlider特性 充分响应各种设备,适应各种屏幕: 支持多种滑动模式,水平.垂直以及淡入淡出效果: 支持图片.视 ...
- Python函数07/有参装饰器/多个装饰器装饰一个函数
Python函数07/有参装饰器/多个装饰器装饰一个函数 目录 Python函数07/有参装饰器/多个装饰器装饰一个函数 内容大纲 1.有参装饰器 2.多个装饰器装饰一个函数 3.今日总结 3.今日练 ...
- SonarQube+Jenkins+Cppcheck实现C++代码扫描
背景:公司部分项目是由C++进行开发,因此对此有需求. sonarqube:docker化安装(alpine系统),版本8.3.1 (build 34397) jenkins:docker化安装,版本 ...
- js 左右切换 局部刷新
//刷新地方的ID,后面ID前必须加空格 $("#gwc").load(location.href + " #gwc");
- Ethical Hacking - GAINING ACCESS(4)
SERVER SIDE ATTACKS - METASPLOIT Metasploit is an exploit development and execution tool. It can als ...
- @RequestMapping中的produces的作用和使用方式
转发:原博客 1.他的作用是指定返回值类型和返回值编码 2.consumes: 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html; 一 ...
- Python基础学习之环境搭建
Python如今成为零基础编程爱好者的首选学习语言,这和Python语言自身的强大功能和简单易学是分不开的.今天我们将带领Python零基础的初学者完成入门的第一步——环境搭建.本文会先来区分几个在P ...