排序在XAML一个DataGrid时的columnHeader箭没有反映 [英] ColumnHeader arrows not reflected when sorting a DataGrid in XAML

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

问题描述

我在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不像是一个普通访客,直到那一刻,我发表了他的解决方案作为一个答案:

添加<一href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcolumn.sortdirection%28v=vs.110%29.aspx"相对=nofollow> SortDirection 的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtextcolumn%28v=vs.110%29.aspx"相对=nofollow> DataGridTextColumn 中的 的DataGrid 。这增加了的columnHeader 箭头。

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

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

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

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