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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With