RadioButton分组的实现
XAML如下
<StackPanel>
<RadioButton GroupName="colorgrp">Red</RadioButton>
<RadioButton GroupName="colorgrp">Blue</RadioButton>
<RadioButton GroupName="numgrp">1</RadioButton>
<RadioButton GroupName="numgrp">2</RadioButton>
<RadioButton>4</RadioButton>
<RadioButton>5</RadioButton>
</StackPanel>
在一个Panel下,若没有指定GroupName则为一组,指定了GroupName为另外一组.
逻辑:一组内,选中一个Button取消其他的Button选中状态.
在没有分组状态下
![]()
即把Button的父容器找出来,然后反选未指定GroupName的Button
分组概念
要把多个Button存为一组,即多个key,每个key对应一个列表,可以以HashTable为基础.
应该由内部控件来调用,否则可能会引起重复的问题
public class RadioGroup
{
[ThreadStatic]
private static Hashtable _groupNameToElements; public static void Register(string groupName, RadioButton radioButton)
{
if (_groupNameToElements == null)
{
_groupNameToElements = new Hashtable(1);
}
lock (_groupNameToElements)
{
ArrayList elements = (ArrayList)_groupNameToElements[groupName];
if (elements == null)
{
elements = new ArrayList(1);
_groupNameToElements[groupName] = elements;
}
else
{
PurgeDead(elements, null);
}
elements.Add(new WeakReference(radioButton));
}
} public static void Unregister(string groupName, RadioButton radioButton)
{
if (_groupNameToElements != null)
{
lock (_groupNameToElements)
{
ArrayList elements = (ArrayList)_groupNameToElements[groupName];
if (elements != null)
{
PurgeDead(elements, radioButton);
if (elements.Count == 0)
{
_groupNameToElements.Remove(groupName);
}
}
}
}
} private static void PurgeDead(ArrayList elements, object elementToRemove)
{
int index = 0;
while (index < elements.Count)
{
WeakReference reference = (WeakReference)elements[index];
object target = reference.Target;
if ((target == null) || (target == elementToRemove))
{
elements.RemoveAt(index);
}
else
{
index++;
}
}
}
}
RadioButton分组的实现的更多相关文章
- PyQt中对RadioButton分组
我们知道在同一widget组件中的radio button有排他属性,为了在一个窗口中显示多组radio button,我们需要对其分组. 通常有两种选择,一种是BoxGroup,另一种是Button ...
- VC++中如何让RadioButton分组,并且互斥
首先让两个RadioButton的Group属性为False. 将两个RadioButton放入一个GroupBox里面,即可如果分成多个组,则将多组Radio分别用GroupBox框起来,并将每组的 ...
- 常用的winform属性和工具箱工具
WinForm: 客户端程序制作 - C/S B/S(外部端,网页端) 不是必须在windows系统上才能运行是在.NET Framework框架上运行 ,在苹果系统上有框架照样可以运行 常用窗体属 ...
- 初识windows程序需要了解的知识点
初识一件事物我们会有陌生,我们慢慢地去了解它就会懂,让我带你们一起了解吧. 一.Form是.Net Framework 定义好的一个最基本的窗体类,具有窗体基本属性和方法 属性 ...
- winform 属性
WinForm为客户端程序必须在.NET Framework框架上运行 一.常用属性: 布局: AutoScroll:当控件内容超出可见区域是否显示滚动条: Autosize:当控件内容有超出时是否自 ...
- WinFom基本属性
常用窗体属性: AutoSroll:如果窗体内容超出了窗体范围,自动出现滚动条.默认是false. AutoSize:调节窗口大小时,保证使窗体内的内容必须全部显示出来. Location:控件左上角 ...
- winform属性
WinForm为客户端程序必须在.NET Framework框架上运行 一.常用属性: 布局: AutoScroll:当控件内容超出可见区域是否显示滚动条: Autosize:当控件内容有超出时是否自 ...
- 【winform】userControl刷新父窗体的datagridview
1.ContextMenuStrip 获取右键控件名称 this.contextMenuScriptScore.SourceControl.Name; //当前控件名 2.radiobutton 分组 ...
- Winform 各种属性、方法、控件
窗体是程序与用户交互的可视界面,窗体也是对象,窗体类定义了生成窗体的模版,实例化一个窗体类就产生了一个窗体. .NET框架类库的System.Windows.Forms命名空间中定义的Form类是所有 ...
随机推荐
- opencv cvtColor dtype issue(error: (-215) )
opencv cvtColor dtype issue(error: (-215) ) 更详细的错误信息如下,color.cpp:9710: error: (-215) depth == CV_8U ...
- 如何获取AppStore软件安装包的路径
本帖最后由 chinald 于 2015-10-16 13:59 编辑 前言:本文介绍在Mac下如何找到AppStore下载的安装包路径,以及如何提取出来供以后使用,希望对大家有所帮助(前提:想要提取 ...
- [TypeStyle] Compose CSS classes using TypeStyle
We will demonstrate composing classes using the utility classes function. classes is also what we re ...
- MySQL5.7 四种日志文件
mysql 日志包括:错误日志,二进制日志,通用查询日志,慢日志等 一:通用查询日志: 记录建立的客户端连接和执行的语句 1)show variables like '%verision%'; 显示数 ...
- 1.2.4 Java Annotation 提要
(本文是介绍依赖注入容器Spring和分析JUnit源码的准备知识) Java Annotation(标注) java.lang.annotation.Annotation是全部Java标注的父接口. ...
- php面试题10(复习)
php面试题10(复习) 一.总结 复习 二.php面试题10 21.谈谈 asp,php,jsp 的优缺点(1 分)(asp要钱,jsp学习成本大)答:ASP 全名 Active Server Pa ...
- Android 5.0中使用JobScheduler
在这篇文章中,你会学习到在Android 5.0中怎样使用JobScheduler API. JobScheduler API同意开发人员在符合某些条件时创建运行在后台的任务. 介绍 在Android ...
- Ntp配置文件详解
1. http://www.ine.com/resources/ntp-authentication.htm 2. http://blog.chinaunix.net/uid-773723-id-16 ...
- SYSTEMTIME 与 time_t 之间的转换,计算2个SYSTEMTIME的时间差
time_t systemtime_to_time_t(const SYSTEMTIME& st) { struct tm gm = {st.wSecond, st.wMinute, st.w ...
- 百度echart--Uncaught Error: Component series.wordCloud not exists. Load it first.
百度echart--Uncaught Error: Component series.wordCloud not exists. Load it first. 一.总结 一句话总结:关注报的错.可以通 ...