在 XAML 中对 DataGrid 进行排序时未反映 ColumnHeader 箭头
我有一个 DataGrid,在 XAML 中定义了一些排序,如下所示:
<CollectionViewSource x:Key="DefaultSort" Source="{Binding SearchResults}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="ExternalOrgNo" Direction="Ascending"/>
<scm:SortDescription PropertyName="ExternalBranchNumber" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
排序已正确应用于 DataGrid,但网格上没有任何排序指示。
查看后面代码中的视图,我看到集合中的 SortDescriptions,并且我尝试刷新视图,但它不起作用。
如何让 ColumnHeader 箭头正确反映视图的 SortDescription 集合的初始状态?
更新:我找到了答案。我将 SortDirection 添加到 DataGrid 中的 DataGridTextColumn 中。这添加了 ColumnHeader 箭头。
<DataGridTextColumn Header="Ext Firm #" Binding="{Binding ExternalOrgNo}" DisplayIndex="4" SortDirection="Ascending" Visibility="Visible" />
<DataGridTextColumn Header="Ext Branch #" Binding="{Binding ExternalBranchNumber}" DisplayIndex="5" SortDirection="Ascending" Visibility="Visible" />
I have a DataGrid with some sorting defined in XAML like so:
<CollectionViewSource x:Key="DefaultSort" Source="{Binding SearchResults}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="ExternalOrgNo" Direction="Ascending"/>
<scm:SortDescription PropertyName="ExternalBranchNumber" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
The sorting is properly applied to the DataGrid but there is no indication of the sorting on the grid.
Looking at the view in the code behind I see the SortDescriptions in the collection and I've tried refreshing the view but it did not work.
How can I have the ColumnHeader arrows properly reflect the status of the view's SortDescription collection initially?
UPDATE: I found an answer. I added the SortDirection to the DataGridTextColumn in the DataGrid. This added the ColumnHeader arrows.
<DataGridTextColumn Header="Ext Firm #" Binding="{Binding ExternalOrgNo}" DisplayIndex="4" SortDirection="Ascending" Visibility="Visible" />
<DataGridTextColumn Header="Ext Branch #" Binding="{Binding ExternalBranchNumber}" DisplayIndex="5" SortDirection="Ascending" Visibility="Visible" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OP 看起来不像是常客,所以在那一刻之前我将他的解决方案作为答案发布:
添加
SortDirection
到DataGridTextColumn
在DataGrid
。这添加了ColumnHeader
箭头。The OP doesn't look like to be a regular visitor so until that moment I post his solution as an answer:
Add the
SortDirection
to theDataGridTextColumn
in theDataGrid
. This added theColumnHeader
arrows.