排序在XAML一个DataGrid时的columnHeader箭没有反映XAML、DataGrid、columnHeader

2023-09-03 03:35:48 作者:傻逼也会恋爱 -

我在XAML定义如下一些排序一个DataGrid:

 < CollectionViewSource X:关键=DefaultSort来源={结合的SearchResult}>
    < CollectionViewSource.SortDescriptions>
        < SCM:SortDescription属性名=ExternalOrgNo方向=升序/>
        < SCM:SortDescription属性名=ExternalBranchNumber方向=升序/>
    < /CollectionViewSource.SortDescriptions>
< / CollectionViewSource>
 

排序是正确应用到DataGrid,但没有迹象显示对电网的排序。

看着在code中的观点的背后,我看到的集合中的SortDescriptions,我已经试过刷新视图,但没有奏效。

我怎么能有箭头的columnHeader正确反映视图的SortDescription收集的状态开始?

更新:我找到了答案。我加入了SortDirection到DataGrid中的DataGridTextColumn。这增加了的columnHeader箭头。

 < D​​ataGridTextColumn标题=外部事务所#绑定={结合ExternalOrgNo}的DisplayIndex =4SortDirection =升序能见度=可见/>
< D​​ataGridTextColumn标题=外部分行#绑定={结合ExternalBranchNumber}的DisplayIndex =5SortDirection =升序能见度=可见/>
 

解决方案

在OP不像是一个普通访客,直到那一刻,我发表了他的解决方案作为一个答案:

添加 SortDirection DataGridTextColumn 中的 的DataGrid 。这增加了的columnHeader 箭头。

 < D​​ataGridTextColumn标题=外部事务所#
                    绑定={结合ExternalOrgNo}
                    的DisplayIndex =4
                    SortDirection =升序
                    能见度=可见/>
< D​​ataGridTextColumn标题=外部分行#
                    绑定={结合ExternalBranchNumber}
                    的DisplayIndex =5
                    SortDirection =升序
                    能见度=可见/>
 
excel 2007中两列数据同时排序 先排好主要列的前提下 再进行次要列排序 并扩展到其他区域该如何操作

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

解决方案

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