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 ...
随机推荐
- P2585 三色二叉树 题解
题目 一棵二叉树可以按照如下规则表示成一个由0.1.2组成的字符序列,我们称之为"二叉树序列S": \[S=\left\{ \begin{aligned} 0 &\ \ 表 ...
- [Mybatis]Mybatis常用操作
Mybatis是目前国内比较流行的ORM框架,特点是可以写灵活的SQL语句,非常适合中小企业的面向数据库开发. 本文总结自己开发过程中常用的Mybatis操作. 一.插入操作 主键自增插入单条 < ...
- 钉钉内置的浏览器怎么改变title
在我项目的开发过程当中,遇到过在钉钉打开的vue写的h5页面,通过在路由切换的时候通过全局的路由钩子函数改变 document.title 的内容失效的问题. const routes = [ { p ...
- 使用Rancher在K8S上部署高性能PHP应用程序
介 绍 PHP是网络上最流行的编程语言之一,许多被广泛使用的内容管理系统都使用它开发,如WordPress和Drupal,并为现代服务器端框架(如Laravel和Symfony)提供核心代码. 尽管P ...
- 数据可视化之powerBI基础(二)PowerBI动态图表技巧:钻取交互
https://zhuanlan.zhihu.com/p/64406366 查看可视化图表的时候,我们可能想深入了解某个视觉对象的更详细信息,或者进行更细粒度的分析,比如看到2017年的总体数据,同时 ...
- 前端03 /css简绍/css选择器
前端03 /css简绍/css选择器 目录 前端03 /css简绍/css选择器 昨日内容回顾 html标签 常用标签 table标签:表格标签 input标签 select下拉框 textarea多 ...
- SpringBoot系列之Elasticsearch极速入门与实际教程
@ 目录 一.什么Elasticsearch? 二.Elasticsearch安装部署 2.1 Elasticsearch安装环境准备 2.2 Docker环境安装Elasticsearch 2.3 ...
- Oracle Database Tools
The following are some products, tools, and utilities you can use to achieve your goals as a databas ...
- 线性dp 之 麻烦的聚餐
题目描述 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想,所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的位置就归第2 ...
- echarts 踩坑 : 为什么效果出不来?看看有没有正确引入
今天我要给 echarts 组件加个 dataZoom 功能,结果发现没有效果. 后来发现是引入 echarts 模块的问题. 如果是按需引入的话,必须引入相应的功能模块才能使用相应的功能. 举例: ...