问题:

  • 添加控件后, 编辑单元格会出现异常
  • 绑定 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. 九度OJ 1028:继续畅通工程 (最小生成树)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3140 解决:1338 题目描述:     省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有 ...

  2. 用CMakeLists.txt组织工程

    1 一个工程会有多个CMakeLists.txt,如何组织这些CMakeLists.txt来构建一个工程? 1.1  最外层一个CMakeLists.txt,是总的CMakeList.txt,在这个里 ...

  3. long_query_time 设置不生效问题

    由于原来的慢查询日志太大了,有1G多,并且其中包含上一次查询优化前的慢sql,所以想收集最近两天的慢查询语句,故 mysql> show global variables like 'slow% ...

  4. High Performance Browser Networking

    Chapter 1. Primer on Latency and Bandwidth As a result, to improve performance of our applications, ...

  5. Java for LeetCode 111 Minimum Depth of Binary Tree

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  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. Linux-3.14.12内存管理笔记【内存泄漏检测kmemleak示例】【转】

    本文转载自:http://blog.chinaunix.net/uid-26859697-id-5758037.html 分析完kmemleak实现后,照常实验一下,以确定功能正常. 如kmemche ...

  8. deep QA 基于生成的chatbot系统

    deep QA: https://github.com/Conchylicultor/DeepQA  基于论文:https://arxiv.org/pdf/1506.05869.pdf  基于生成的c ...

  9. linux 进程学习笔记-消息队列messagequeue

    可以想象,如果两个进程都可以访问同一个队列:其中一个进程(sender)向其中写入结构化数据,另外一个进程(receiver)再从其中把结构化的数据读取出来.那么这两个进程就是在利用这个队列进行通信了 ...

  10. nginx rewrite 导致验证码不正确

    配置nginx里url rewrite的时候,为了使浏览器地址栏的URL保持不变, 使用proxy_pass反向代理,但发现每次都会生成新的jsessionid 解决方法,配置中增加 proxy_co ...