Windows Community Toolkit 4.0 - DataGrid - Overview
概述
Windows Community Toolkit 4.0 于 2018 月 8 月初发布:Windows Community Toolkit 4.0 Release Note. 4.0 版本相较于 3.0,增加了 DataGrid 等控件,Sample App 支持了 Fluent Design 设计和明暗两种风格,修复了遗留的控件 BUG,接下来我们主要看一下 DataGrid 控件的实现。
DataGrid 控件是一个可以展示多行多列数据集合的控件,相信大家在 Silverlight WPF 等平台开发中都有过接触,该控件非常适合用来展示数据表格,可以完全是文本内容展示,也可以在数据中包含按钮等操作;另外控件还支持筛选,分组等操作需求。
由于 DataGrid 控件涉及到的功能比较复杂,代码量也比较大,我们会分为几篇文章来详细讲解。而本篇,我们会先针对 DataGrid 控件的整体实现和使用做介绍。
下面是 Windows Community Toolkit Sample App 的示例截图和 code/doc 地址:

Windows Community Toolkit Doc - DataGrid
Windows Community Toolkit Source Code - DataGrid
Namespace: Microsoft.Toolkit.Uwp.UI.Controls; Nuget: Microsoft.Toolkit.Uwp.UI.Controls.DataGrid;
开发过程
代码结构分析
本篇我们先对 DataGrid 的整体代码结构做概览分析,后续会分几篇文章来分析每个重要的类和方法实现。来看一下 DataGrid 的代码结构:

可以看到,DataGrid 的代码结构上是一整个 Project,而在 Nuget 上也能体现。接下看一下几个文件夹的组成和其中重要的类:
1. CollectionViews
CollectionViews 是 DataGrid 的数据部分,可以看到 CollectionView 是基类,EnumerableCollectionView 和 ListCollectionView 继承自它,而这两个类分别代表枚举类的集合,以及列表类的集合。这两个类,都会在 DataGrid 获取数据源时被使用到。

2. Utilities
Utilities 是 DataGrid 控件的基础类和帮助类集合,可以看到涉及到绑定,数值相等(接近)判断,扩展功能,索引值映射,键盘帮助类,值范围,类型帮助类,UI 设置帮助类,校验类,可视状态类和内存管理监听类;后面我们会详细讲解每个类的重点实现部分。

3. DataGrid
DataGrid 控件的最重要实现在 DataGrid 文件夹中,一共有 50 多个类。我们可以先看一遍这里类的大致作用,后面会详细讲解每个类的代码实现:
- Automation - DataGrid UIA 实现
- DataGrid,DataGridColumn,DataGridRow,DataGridCell 控件类,控件头,基于这些类的实现类;
- DataGrid,DataGridColumn,DataGridRow,DataGridCell 相关事件处理类;
- DataGrid,DataGridColumn,DataGridRow,DataGridCell 相关数据类;


调用示例
我们来看一下 DataGrid 控件的调用方式,先看一下 XAML 的简单实现:
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
<controls:DataGrid x:Name="dataGrid1"
Height="600" Margin="12"
AutoGenerateColumns="True"
ItemsSource="{x:Bind MyViewModel.Customers}" />
接着看一下数据源的简单代码:
public class Customer
{
public String FirstName { get; set; }
public String LastName { get; set; }
public String Address { get; set; }
public Boolean IsNew { get; set; }
public Customer(String firstName, String lastName,
String address, Boolean isNew)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Address = address;
this.IsNew = isNew;
}
public static List<Customer> Customers()
{
] {
new Customer("A.", "Zero",
"12 North Third Street, Apartment 45",
false),
new Customer("B.", "One",
"34 West Fifth Street, Apartment 67",
false),
new Customer("C.", "Two",
"56 East Seventh Street, Apartment 89",
true),
new Customer("D.", "Three",
"78 South Ninth Street, Apartment 10",
true)
});
}
}
看一下运行结果:

总结
到这里我们就把 Windows Community Toolkit 4.0 中的 DataGrid 概览和代码整体结构讲解完成了,希望能对大家更好的理解和使用这个功能有所帮助。后续会对该控件做系列的详细讲解。
最后,再跟大家安利一下 WindowsCommunityToolkit 的官方微博:https://weibo.com/u/6506046490, 大家可以通过微博关注最新动态。
衷心感谢 WindowsCommunityToolkit 的作者们杰出的工作,感谢每一位贡献者,Thank you so much, ALL WindowsCommunityToolkit AUTHORS !!!
Windows Community Toolkit 4.0 - DataGrid - Overview的更多相关文章
- Windows Community Toolkit 4.0 - DataGrid - Part01
概述 在上面一篇 Windows Community Toolkit 4.0 - DataGrid - Overview 中,我们对 DataGrid 控件做了一个概览的介绍,今天开始我们会做进一步的 ...
- Windows Community Toolkit 4.0 - DataGrid - Part03
概述 在上面一篇 Windows Community Toolkit 4.0 - DataGrid - Part02 中,我们针对 DataGrid 控件的 Utilities 部分做了详细分享.而在 ...
- Windows Community Toolkit 4.0 - DataGrid - Part02
概述 在上面一篇 Windows Community Toolkit 4.0 - DataGrid - Part01 中,我们针对 DataGrid 控件的 CollectionView 部分做了详细 ...
- Windows Community Toolkit 3.0 - UniformGrid
概述 UniformGrid 控件是一个响应式的布局控件,允许把 items 排列在一组均匀分布的行或列中,以填充整体的可用显示空间,形成均匀的多个网格.默认情况下,网格中的每个单元格大小相同. 这是 ...
- Windows Community Toolkit 3.0 - InfiniteCanvas
概述 InfiniteCanvas 是一个 Canvas 控件,它支持无限画布的滚动,支持 Ink,文本,格式文本,画布缩放操作,撤销重做操作,导入和导出数据. 这是一个非常实用的控件,在“来画视频” ...
- Windows Community Toolkit 3.0 - Gaze Interaction
概述 Gaze Input & Tracking - 也就是视觉输入和跟踪,是一种和鼠标/触摸屏输入非常不一样的交互方式,利用人类眼球的识别和眼球方向角度的跟踪,来判断人眼的目标和意图,从而非 ...
- Windows Community Toolkit 3.0 - CameraPreview
概述 Windows Community Toolkit 3.0 于 2018 年 6 月 2 日 Release,同时正式更名为 Windows Community Toolkit,原名为 UWP ...
- Windows Community Toolkit 3.0 新功能 在WinForms 和 WPF 使用 UWP 控件
本文告诉大家一个令人震惊的消息,Windows Community Toolkit 有一个大更新,现在的版本是 3.0 .最大的提升就是 WinForm 和 WPF 程序可以使用部分 UWP 控件. ...
- Windows Automation API 3.0 Overview
https://www.codemag.com/article/0810042 While general accessibility requirements (such as font color ...
随机推荐
- php post接口,登录功能
登录功能同注册功能一样,都是使用 post 方法,在执行 sql 语句时,同样要使用 "select * from 表名 where 键名 = 参数" 的查询方式,不同的是: 注册 ...
- Node.js学习记录(一)--安装设置篇
安装Node window window上安装node可选择以下两种方式: 方式一:直接进入官网下载安装 进入node.js官网点击windows,选择.msi后缀的,根据自己的电脑选择对应的64位或 ...
- 银盒子智慧餐厅硬件尺寸规格&推荐机型
- 洗礼灵魂,修炼python(66)--爬虫篇—BeauitifulSoup进阶之“我让你忘记那个负心汉,有我就够了”
说明一下,这个标题可能有点突兀,结合上一篇一起看就行 前面已经对BeautifulSoup有了了解了,相信你基本已经学会怎么获取网页数据了,那么BeautifulSoup这么吊,还有没有其他的功能呢? ...
- Sql Server XML
实验数据: Create table xmldata (name NVARCHAR(20), age int, sex NVARCHAR(5) ) INSERT INTO xmldata VALUES ...
- mysql 最左匹配 联合索引
mysql建立多列索引(联合索引)有最左前缀的原则,即最左优先,如: 如果有一个2列的索引(col1,col2),则已经对(col1).(col1,col2)上建立了索引:如果有一个3列索引(col1 ...
- c/c++ 标准容器 vector的内存空间是如何自动增长的
c/c++ 标准容器 vector的内存空间是如何自动增长的 vector,string,deque的内存存储机制:在一个连续的内存空间存储,所以才支持下标操作. vector的课题:由于容器的大小是 ...
- Windows Server 2016-域站点链接及子网调整
很多情况下我们在判别域控间或者域中各站点同步是否正常往往的操作内容就是查看两台域控间PING或者解析是否正常,或者查看双方防火墙是否关闭,但实际情况下我们需要注意的是,保证站点间Active Dire ...
- Windows Server 2016-Win Ser 2016已删减内容
本章与大家简单聊聊已经从Windows Server 2016产品中删减掉或者计划在以后潜在删除的功能或者模块. 文件服务器 共享和存储管理贴靠-Microsoft 管理控制台已删除. 相反,请执行以 ...
- Windows Server 2016-Win Ser 2016新增功能
本来想着整个系列都是与Active Directory相关的内容,上一章节我们应读者要求补充了Window Server 2016标准版与数据中心版的区别,鉴于读者的疑惑,从本章节开始补充三到五章与W ...