Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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" />
like image 606
Matt Avatar asked Jul 25 '11 18:07

Matt


1 Answers

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" />
like image 190
rene Avatar answered Oct 06 '22 00:10

rene