WPF DataGridComboBox绑定enum
来源:互联网 发布:昆明达内大数据培训 编辑:程序博客网 时间:2024/05/22 13:04
定义Enum
public enum Types { 不变, 随机, 波动 }
前台代码
<Window.Resources> <ObjectDataProvider x:Key="myEnum" MethodName="GetValues" ObjectType="{x:Type core:Enum}"> <ObjectDataProvider.MethodParameters> <x:Type Type="local:Types"/> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources>
<DataGrid Name="dg_render" Margin="0,20,20,0" MinWidth="250px" CanUserAddRows="False" ItemsSource="{Binding}" AutoGenerateColumns="False"> <DataGrid.Columns> <!--省略其他--> <DataGridComboBoxColumn Header="类型" SelectedValueBinding="{Binding Type}" ItemsSource="{Binding Source={StaticResource myEnum}}"> </DataGridComboBoxColumn> </DataGrid.Columns> </DataGrid>
注意将Type类的命名空间引入到xaml中。
后台数据绑定
- 绑定DataGrid
ocr = new ObservableCollection<RenderHelper>();...this.dg_render.ItemsSource = ocr;
- 编写RenderHelper类
class RenderHelper: INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged;private Types type;public Types Type { get { return type; } set { type = value; if (this.PropertyChanged != null) { this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Type")); } } } ...}
运行效果
0 0
- WPF DataGridComboBox绑定enum
- DataGridComboBox
- WPF-绑定
- WPF绑定
- DropDownList 绑定 枚举 Enum
- [WPF] Binding Enum to ComboBox
- WPF Binding ItemsSource to Enum
- jsf之enum的绑定
- 绑定Enum枚举到combobox
- WPF之数据绑定
- WPF之数据绑定
- WPF之绑定数据
- wpf数据绑定常见问题
- WPF数据绑定
- WPF 数据绑定[1]
- WPF 数据绑定[2]
- WPF 数据绑定[3]
- WPF 数据绑定[4]
- windows 下 CMD 查询本机开了哪些端口 并查看开启端口的软件
- 正则表达式语法和示例
- 大数据工具/框架
- JSP
- 关于spring配置中the prefix "tx" for element "tx:annotation-driven" is not bound 问题的处理
- WPF DataGridComboBox绑定enum
- js密码强度验证代码
- 压缩文件文件流
- JAVA FTP文件上传下载删除
- 基于AT89C51教程之软件篇(一)头文件的故事
- C语言中 ln(以自然对数e为底) lg(以十为底) 以及logab(以a为底,b为真数)的相关知识
- Android 第七天(上午)
- 总结:四张图读懂手游发行公司的日常工作
- Kafka 初识