问题:

  • 添加控件后, 编辑单元格会出现异常
  • 绑定 ItemsSource 属性后, 更新绑定对象的数据, UI 不刷新
  • 如何显示控件中 ComboBox 类型

解决方法:

  • 绑定 ItemsSource 属性即可
  • 每次更新绑定对象后, 先 ItemsSource = null, 再重新绑定 ItemsSource
  • 使用静态类型设置 ComboBox 的 ItemsSource, 如下所示:
<Window
    ...
    xmlns:core="clr-namespace:System;assembly=mscorlib"
    xmlns:local="<!--  指向枚举类型所在的命名空间  -->"
    ...>
    <Window.Resources>
        <ResourceDictionary>
            ...
            <!--  Create list of enumeration values  -->
            <ObjectDataProvider
                x:Key="myEnum"
                MethodName="GetValues"
                ObjectType="{x:Type core:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type Type="local:<!--  枚举类型  -->" />
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
        </ResourceDictionary>
    </Window.Resources>
    <Grid>
        ...
        <DataGrid
            ...
            <DataGrid.Columns>
                ...
                <materialDesign:MaterialDataGridComboBoxColumn
                    Header="<!--  列标题  -->"
                    ItemsSource="{Binding Source={StaticResource myEnum}}"
                    SelectedValueBinding="{Binding <!--  绑定数据  -->}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

参考:

Working Experience - WPF 中 DataGrid 控件的应用的更多相关文章

  1. WPF中DataGrid控件内Button的Command和CommandParameter的绑定

    场景:视频上传功能,上传列表使用DataGrid控件,视频有不同的状态对应不同的操作,DataGrid中最后一列为操作列,里面是Button控件.希望点击Button后执行对应的操作,但是设置Butt ...

  2. WPF中DataGrid控件的过滤(Filter)性能分析及优化

    DataGrid控件是一个列表控件, 可以进行过滤,排序等.本文主要针对DataGrid的过滤功能进行分析, 并提供优化方案. 1)DataGrid的过滤过程:      用户输入过滤条件       ...

  3. wpf 中DataGrid 控件的样式设置及使用

    本次要实现的效果为: 这个DataGrid需要绑定一个集合对象,所以要先定义一个Experience类,包含三个字段 /// <summary> /// 定义工作经历类 /// </ ...

  4. WPF中Datagrid控件添加行号

    /// <summary> /// 导入Excel文件按钮 /// </summary> /// <param name="sender">&l ...

  5. WPF中查找控件的扩展类

    在wpf中查找控件要用到VisualTreeHelper类,但这个类并没有按照名字查找控件的方法,于是搜索网络,整理出下面这个类,感觉用起来很是方便. 贴出来,供大家参考. /// <summa ...

  6. WPF的DataGrid控件从excel里复制数据然后粘贴

    WPF的DataGrid控件不能像winform的DataGridView控件一样,支持值的粘贴.WPF的DataGrid控件本质上是跟数据绑定联系在一起,所以需要进行复制粘贴的操作,可以在wpf里用 ...

  7. WPF 4 DataGrid 控件(进阶篇一)

    原文:WPF 4 DataGrid 控件(进阶篇一)      上一篇<WPF 4 DataGrid 控件(自定义样式篇)>中,我们掌握了DataGrid 列表头.行表头.行.单元格相关的 ...

  8. WPF 4 DataGrid 控件(进阶篇二)

    原文:WPF 4 DataGrid 控件(进阶篇二)      上一篇<WPF 4 DataGrid 控件(进阶篇一)>中我们通过DataGridTemplateColumn 类自定义编辑 ...

  9. WPF 4 DataGrid 控件(基本功能篇)

    原文:WPF 4 DataGrid 控件(基本功能篇)      提到DataGrid 不管是网页还是应用程序开发都会频繁使用.通过它我们可以灵活的在行与列间显示各种数据.本篇将详细介绍WPF 4 中 ...

随机推荐

  1. mac上完整卸载删除.简单粗暴无脑:androidstudio删除方案

    如果你是mac  ,你删除as ,删不干净也正常,你会发现安装的时候,前面的东西也在.配置文件在,会导致你以前的错误不想要的东西都在. 废话不多说,复制粘贴就是干!!!!~~~~~~~~ 第一步: 复 ...

  2. React-Native开源项目学习

    https://github.com/liuhongjun719/react-native-DaidaiHelperNew 借贷助手https://github.com/liuhongjun719/r ...

  3. wepy 实现 用户名登录与短信验证码登录

    wepy 实现 用户名登录与短信验证码登录

  4. To discount or not to discount in reinforcement learning: A case study comparing R learning and Q learning

    https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/kaelbling96a-html/node26.html [平均-打折奖励] Schwa ...

  5. 【python】使用python写windows服务

    背景 运维windows服务器的同学都知道,windows服务器进行批量管理的时候非常麻烦,没有比较顺手的工具,虽然saltstack和ansible都能够支持windows操作,但是使用起来总感觉不 ...

  6. Java for LeetCode 101 Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  7. ContextLoaderListener容器初始化

    http://blog.csdn.net/qq924862077/article/details/52769754 <context-param> <param-name>co ...

  8. Spring Boot2.0之 原理—创建内置Tomcat容器

    前面所述的https://www.cnblogs.com/toov5/p/9823728.html 中的第一条先不赘述了,就是玩了maven 重点介绍后两条 首先内置Tomcat: SpringBoo ...

  9. 右上角鼠标滑过展开收缩动画效果js代码的演示页面

    http://files.cnblogs.com/files/tanlingdangan/top_right.rar.gz 右上角鼠标滑过展开收缩动画效果js代码的演示页面http://www.51x ...

  10. iOS审核总被拒?腾讯教你提升iOS审核通过率!

    作者:Jamie,腾讯开发工程师,在iOS预审和ASO优化领域从事专项测试相关工作,为腾讯游戏近100个产品提供专项服务. 商业转载请联系腾讯WeTest获得授权,非商业转载请注明出处. WeTest ...