WPF工具包的DataGrid排序、更改反映到数据源?

发布于 2024-09-15 22:52:04 字数 73 浏览 1 评论 0原文

当我对 DataGrid 中的一列(单击标题列)进行排序时,UI 上的更改(行顺序)是否反映回数据源?我使用 List 对象作为源。

When I sort one of the columns (click the header column) in DataGrid, does the change on UI (the row order) reflected back to the data source ? I use List object as source.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世蒼涼 2024-09-22 22:52:04

不会,UI 排序对数据没有影响。

还有另一种方法可以直接对数据进行排序(实际上是数据的表示形式),但将其连接到正常的 UI 功能(单击标题进行排序)可能会涉及更多一些,并且还有其他一些缺点: ICollectionView 中的集合(例如 ListCollectionView)并使用 SortDescriptions 或自定义排序谓词对项目进行排序; ICollectionView 将位于源集合和 UI 之间,您可以从中获取排序后的项目。

此外,您也可以直接对源集合进行排序(手动或使用可排序集合),但同样,您需要将数据网格标头连接到排序代码,这意味着拦截标题并绘制适当的字形以进行排序提示等。

No, the UI sort has no effect on the data.

There is another way to sort directly the data (actually, the representation of the data), but connecting it to the normal UI functionality (clicking on a header to sort) might be a bit more involved and also has several other downsides: wrap the collection in an ICollectionView (ListCollectionView for instance) and use SortDescriptions or custom sort predicates to sort the items; the ICollectionView will stand between the source collection and the UI and you can get the sorted items from it.

Also, you can sort the source collection directly as well (either manually or by using a sortable collection), but again, you need to connect the datagrid headers to the sorting code, which means something along the lines of intercepting the click events of the headers and drawing appropriate glyphs for sort hints etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文