1、添加MarkupExtension

public class EnumToSourceExtension : MarkupExtension
{
private Type _type; public EnumToSourceExtension(Type type)
{ _type = type;
} public override object ProvideValue(IServiceProvider serviceProvider)
{
return Enum.GetValues(_type)
.Cast<object>()
.Select(e => new
{
Value = (int)e,
DisplayName = e.ToString(),
Desc = EnumHelper.GetDescription(_type, e)
}); ;
}
}

2、绑定

<ComboBox ItemsSource="{extensions:EnumToSource {x:Type enums:AnalysisType}}"
DisplayMemberPath="Desc" SelectedValuePath="Value"> </ComboBox>

Binding Enum to ComboBox的更多相关文章

  1. Bind Enum to Combobox.SelectedIndex

    原文:Bind Enum to Combobox.SelectedIndex Do you mean that you want to bind a variable (not a property) ...

  2. WPF standard ComboBox Items Source Change Issue

    Today I encountered an issue with the WPF standard CombBox where if the bound ItemsSource (collectio ...

  3. Binding的Source从何而来?

    I. Binding to Object 1. Binding data using ObjectDataProvider AC:Let’s say there is a CLR based data ...

  4. WPF中实现多选ComboBox控件

    在WPF中实现带CheckBox的ComboBox控件,让ComboBox控件可以支持多选. 将ComboBox的ItemsSource属性Binding到一个Book的集合, public clas ...

  5. Win10 UWP 开发系列:使用多语言工具包让应用支持多语言

    之前我在一篇blog中写过如何使用多语言工具包,见http://www.cnblogs.com/yanxiaodi/p/3800767.html 在WinEcos社区也发布过一篇详细的文章介绍多语言工 ...

  6. 编写 WPF DataGrid 列模板,实现更好的用户体验

    Julie Lerman 下载代码示例 最近我在为一个客户做一些 Windows Presentation Foundation (WPF) 方面的工作. 虽然我提倡使用第三方工具,但有时也会避免使用 ...

  7. 【我们一起写框架】MVVM的WPF框架(三)—数据控件

    这世上,没人能一次性写出完美无缺的框架:因为,任何一个框架都需要项目的淬炼,然后才能升华,趋近完美. 所以,框架是个反复修改的东西,最终形成的东西. 如果你学了一点技术,觉得自己可以写出框架了,觉得自 ...

  8. 【WPF】ComboBoxItem的禁用

    需求:下拉列表ComboBox中,要求部分Item不可用.效果是鼠标一上去后不获得焦点,且无法点击. 前台XAML界面: <!-- 下拉列表:省份 --> <ComboBox Gri ...

  9. WPF中。。DataGrid 实现时间控件和下拉框控件

    DatePicker 和新的 DataGrid 行 用户与 DataGrid 中日期列的交互给我造成了很大的麻烦. 我通过将一个 Data Source 对象拖动到 WPF 窗口上,创建了一个 Dat ...

随机推荐

  1. C#之经理评分系统

    PM类,几乎全是属性 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  2. 网上干货 ElasticSearch详解与优化设计

    https://blog.csdn.net/joez/article/details/52171199?locationNum=3&fps=1 分析得很好,需要仔细阅读 问题遗留点: Fiel ...

  3. 5.13Junit单元测试-反射-注解

    一.Junit单元测试 * 测试分类: 1.黑盒测试:不需要写代码,给输入值,看程序是否能够输出期望的值 2.白盒测试:需要些代码的.关注程序具体的执行流程 Junit使用:白盒测试 步骤: 1.定义 ...

  4. Django学习案例一(blog):五. 开发主页(博客列表展示)

    主页是一个“博客列表”页.博客要按发布时间的倒序来排列,每个博客都要包含标题.作者.分类.发布时间的显示(年-月-日 时:分)及节选的正文内容(前 100 个字).点击单独的博客可以进入其详情页. 1 ...

  5. 图像局部显著性—点特征(GLOH)

    基于古老的Marr视觉理论,视觉识别和场景重建的基础即第一阶段为局部显著性探测.探测到的主要特征为直觉上可刺激底层视觉的局部显著性--特征点.特征线.特征块. 相关介绍:局部特征显著性-点特征(SIF ...

  6. HDU_1517_博弈(巧妙规律)

    A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  7. redis与其可视化工具在win7上的安装

    步骤 1.下载安装Redis服务. 2.调用执行文件创建服务器以及测试缓存. 3.使用可视化工具redis-desktop-manager管理查询缓存. 1.下载安装Redis服务. 下载地址:htt ...

  8. react获取url查询参数

    继承自React.Component的this.props.location.query对象下有当前url的各种查询参数.简单的例子:在控制台打印这个对象 import React from 'rea ...

  9. CF319E Ping-Pong 线段树 + vector + 思维

    Code: #include<bits/stdc++.h> #define N 3000009 #define maxn 3000009 #define ll long long #def ...

  10. BZOJ4756 [USACO17JAN]Promotion Counting晋升者计数

    Description The cows have once again tried to form a startup company, failing to remember from past ...