开发者

ColumnHeader arrows not reflected when sorting a DataGrid in 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>

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 Co开发者_开发百科lumnHeader 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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜