在 XAML 中对 DataGrid 进行排序时未反映 ColumnHeader 箭头 [英] ColumnHeader arrows not reflected when sorting a DataGrid in XAML

查看:15
本文介绍了在 XAML 中对 DataGrid 进行排序时未反映 ColumnHeader 箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DataGrid,其中在 XAML 中定义了一些排序,如下所示:

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>

排序已正确应用于 DataGrid,但网格上没有排序的指示.

The sorting is properly applied to the DataGrid but there is no indication of the sorting on the grid.

查看后面代码中的视图,我看到集合中的 SortDescriptions,我尝试刷新视图,但没有奏效.

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.

最初如何让 ColumnHeader 箭头正确反映视图的 SortDescription 集合的状态?

How can I have the ColumnHeader arrows properly reflect the status of the view's SortDescription collection initially?

更新:我找到了答案.我将 SortDirection 添加到 DataGrid 中的 DataGridTextColumn.这添加了 ColumnHeader 箭头.

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" />

推荐答案

OP 看起来不像是常客,所以直到那一刻我发布他的解决方案作为答案:

The OP doesn't look like to be a regular visitor so until that moment I post his solution as an answer:

添加 SortDirectionDataGridTextColumn.control.datagrid%28v=vs.110%29.aspx" rel="nofollow">DataGrid.这添加了 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" />

这篇关于在 XAML 中对 DataGrid 进行排序时未反映 ColumnHeader 箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆