Cgdata.FastWpfGrid
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Cgdata.FastWpfGrid --version 1.0.1
NuGet\Install-Package Cgdata.FastWpfGrid -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cgdata.FastWpfGrid" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cgdata.FastWpfGrid" Version="1.0.1" />
<PackageReference Include="Cgdata.FastWpfGrid" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cgdata.FastWpfGrid --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Cgdata.FastWpfGrid, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cgdata.FastWpfGrid@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cgdata.FastWpfGrid&version=1.0.1
#tool nuget:?package=Cgdata.FastWpfGrid&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FastWpfGrid
FastWpfGrid 是一个高性能的 WPF DataGrid 控件,专为大数据集设计,采用强制数据虚拟化机制。通过 WriteableBitmap 进行像素级渲染,而非使用 WPF 模板,从而实现极致的滚动和渲染性能。
核心特性
- 高性能渲染 — 基于 WriteableBitmap 的像素级绘制,避免 WPF 可视化树的性能开销
- 强制数据虚拟化 — 模型按需提供数据,仅加载可见区域的数据
- 冻结行/列 — 支持冻结行和冻结列,在滚动时保持固定
- 隐藏行/列 — 可通过模型动态隐藏行和列
- 转置模式 — 行列互换显示(
IsTransposed属性) - Excel 式框选 — 鼠标拖拽进行多单元格选择
- 行内编辑 — 单元格直接编辑支持
- ClearType 渲染 — 可选的 ClearType 文本渲染,提升文字清晰度
- 富文本单元格 — 单元格支持多文本块(加粗、斜体、颜色)和图片
- 部分重绘 — 仅重绘变化的单元格,避免全量刷新
- 灵活行高 — 可选的可变行高模式
- 多视图支持 — 一个模型可同时绑定多个控件实例
- DataTable 适配器 — 内置
DataTableGridModel,开箱即用支持System.Data.DataTable
安装
通过 NuGet 安装:
Install-Package Cgdata.FastWpfGrid
或使用 .NET CLI:
dotnet add package Cgdata.FastWpfGrid
快速上手
1. 创建数据模型
继承 FastGridModelBase 并重写关键方法:
using FastWpfGrid;
public class MyGridModel : FastGridModelBase
{
private Dictionary<Tuple<int, int>, string> _editedCells = new();
public override int ColumnCount => 100;
public override int RowCount => 1000;
public override string GetCellText(int row, int column)
{
var key = Tuple.Create(row, column);
if (_editedCells.TryGetValue(key, out var value))
return value;
return $"单元格 {row + 1},{column + 1}";
}
public override void SetCellText(int row, int column, string value)
{
_editedCells[Tuple.Create(row, column)] = value;
}
}
2. 在 XAML 中使用
<Window xmlns:fwg="clr-namespace:FastWpfGrid;assembly=FastWpfGrid">
<fwg:FastGridControl x:Name="MyGrid" />
</Window>
3. 绑定模型
MyGrid.Model = new MyGridModel();
使用 DataTable 适配器
如果数据源是 DataTable,可以直接使用内置适配器:
var dataTable = GetDataFromSomewhere();
MyGrid.Model = new DataTableGridModel(dataTable);
模型接口
实现 IFastGridModel 接口或继承 FastGridModelBase 来提供数据:
| 方法 | 说明 |
|---|---|
ColumnCount |
列数 |
RowCount |
行数 |
GetCellText(row, column) |
获取单元格文本 |
SetCellText(row, column, value) |
设置单元格文本 |
GetCell(row, column) |
获取单元格详细信息(背景色、内容块等) |
GetRowHeader(row) |
获取行头内容 |
GetColumnHeader(column) |
获取列头内容 |
GetGridHeader(view) |
获取左上角网格头内容 |
GetHiddenColumns() |
返回隐藏的列集合 |
GetFrozenColumns() |
返回冻结的列集合 |
GetHiddenRows() |
返回隐藏的行集合 |
GetFrozenRows() |
返回冻结的行集合 |
依赖关系
- WriteableBitmapEx(项目内包含,用于像素级渲染)
支持的目标框架
- .NET 8.0 (Windows)
- .NET 10.0 (Windows)
许可证
本项目基于开源协议发布。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. net10.0-windows7.0 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0-windows7.0
- Cgdata.WriteableBitmapEx.Wpf (>= 1.0.0)
- System.Data.DataSetExtensions (>= 4.5.0)
-
net8.0-windows7.0
- Cgdata.WriteableBitmapEx.Wpf (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.