工作中用到了一组RadioButton对应一组数据的情况,这个时候最好能将一组RadioButton绑定Enum。

步骤

1.MyControl库中Type.cs中定义Enum

 namespace MyControl.MyRadioButton
{
public enum Type { A, B, C, }
}

2.MyUseControl的ViewModel文件夹下testViewModel.cs中

 private Type m_myType;
public Type MyType
{
  get{ return m_myType;}
  set
  {
    if(m_myType != value) { m_myType = value; }
  }
}

3.MyUserControl的Converses文件夹下Enum2BoolConverter.cs中

 class Enum2BoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value == null ? false : value.Equals(parameter);
} public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value != null && value.Equals(true) ? parameter : Binding.DoNothing;
}
}

4.在test.xaml文件中需要引用MyControl库

 xmlns:locals="clr-namespace:MyControl.MyRadioButton;assembly=MyControl"
<!--引用Converses命名空间-->
xmlns:converter="clr-namespace:MyUseControl.Converters"
<UserControl.Resources>
<converter:Enum2BoolConverter x:Key="enum2BoolConverter" />
</UserControl.Resources>

5.test.xaml文件中RadioButton的IsChecked属性中

IsChecked="{Binding MyType,
Converter={StaticResource enum2BoolConverter},
    ConverterParameter={x:Static locals:Type.A}
}"

WPF一组Radio与enum绑定的更多相关文章

  1. 设置为互斥按钮的一组Radio按钮的用法

    设置为互斥按钮的一组Radio,只需要将第一个Radio的Group属性设置为True,并为之映射变量(DDX),其余radio的Group属性设置为False,不需要映射变量. 否则会出现不是互斥按 ...

  2. [No000012E]WPF(6/7):概念绑定

    WPF 的体系结构,标记扩展,依赖属性,逻辑树/可视化树,布局,转换等.今天,我们将讨论 WPF 最重要的一部分——绑定.WPF 带来了优秀的数据绑定方式,可以让我们绑定数据对象,这样每次对象发生更改 ...

  3. Visual Studio中Radio Button组绑定变量方法(DDX_Radio方法)

    需求描述:Visual Studio 创建的界面程序中又许多 Radio Button,希望这些所有的Radio Button统一绑定到一个变量上,这个变量一旦改变,Radio Button的选中状态 ...

  4. WPF Toolkit AutoCompleteBox 实体类绑定 关键字自定义关联搜索匹配

    原文:WPF Toolkit AutoCompleteBox 实体类绑定 关键字自定义关联搜索匹配 WPF Toolkit AutoCompleteBox 实体类绑定 关键字自定义关联搜索匹配 网上的 ...

  5. WPF DataGrid 双击行 获得绑定数据

    原文:WPF DataGrid 双击行 获得绑定数据 1)增加事件 2)增加对象获取 1)事件代码 Datagrid 增加事件 MouseDoubleClick="dataGrid_Mous ...

  6. WPF DATAGrid 空白列 后台绑定列 处理

    原文:WPF DATAGrid 空白列 后台绑定列 处理 AutoGenerateColumns <DataGrid x:Name="dataGrid" Margin=&qu ...

  7. 总结:WPF中MultiBinding多值绑定的方法

    原文:总结:WPF中MultiBinding多值绑定的方法 一.Xaml中绑定代码: <TextBlock  Grid.Row="5" Grid.Column="3 ...

  8. WPF Radio组的绑定

    都是控件编,RadioButtion 简单绑定使用,model.cs下边定义属性 private int _isSuccess; public int IsSuccess { get { return ...

  9. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

随机推荐

  1. Centos 7 安装composer和Laravel

    composer安装 我安装了lnmp到Centos7里,所以可以直接运行curl -sS https://getcomposer.org/installer | php把安装的composer.ph ...

  2. 颜色空间之CIE2000色差公式

    CIEDE2000色差公式   为了进一步改善工业色差评价的视觉一致性,CIE专门成立了工业色差评价的色相和明度相关修正技术委员会TC1-47(Hue and Lightness Dependent ...

  3. GDI+_从Bitmap里得到的Color数组值解决方案

    ' InkHin_ZhiZhuo ' Date :2019.2.18 ' E-mail lqx@tyningling.Top 'This function and Module is written ...

  4. 爬了招聘网站之后,总结Python学习的几点建议

    来源商业新知网,原标题::爬了招聘网站之后,给你几点学习Python的建议 Python语言相关的岗位非常多,有运维,有自动化测试,有后端开发,有机器学习,如果想要快速上手,并且有不错的就业,那就推荐 ...

  5. Django中的auth模块

    from django.contrib import auth authenticate() 提供了用户认证功能,即验证用户名以及密码是否正确,一般需要username .password两个关键字参 ...

  6. Version Control/Git,SVN

    一.Version Control 1.什么是Version Control 版本控制(Version Control)是指对软件开发过程中各种程序代码.配置文件及说明文档等文件变更的管理,是软件配置 ...

  7. CSS初识盒子

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. UVALive 3942 Remember the Word

    题意:给出一个由S个不同单词组成的字典和一个长字符串.把这个字符串分解成若干个单词的连接(单词可以重复 使用),有多少种方法? Sample Input abcd 4 a b cd ab Sample ...

  9. 基于SDL2实现俄罗斯方块

    俄罗斯方块有多种旋转规则,我这里采用的是SRS.如果要改变旋转规则的话也很方便. SRS: 内容后续补充.. 代码:https://github.com/CknightX/sdl_Tetris 素材来 ...

  10. Python学习笔记4基本数据类型

    start:16:00 1.Python基本数据类型 (1)数字类型及其操作 整数类型 浮点数类型 浮点数间运算存在不确定尾数,不是bug 复数类型 数值运算操作符 (2)数值运算函数    . 2. ...