Without Custom Sorting | Custom Sorting |
---|---|
- Enable custom sorting for DataGrid by
UseCustomSort
- Set
CustomSorter
orCustomSorterType
for columns you want apply custom sorting.- Sorter must implement
IComparer
- Sorter must have default constructor in order to use
CustomSorterType
- Sorter must implement
<DataGrid attached:DataGridHelpers.UseCustomSort="True" ItemsSource="{Binding Items}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn attached:DataGridHelpers.CustomSorterType="{x:Type comparers:StrLogicalComparer}" Binding="{Binding CodeText}" Header="Code" />
<DataGridTextColumn Header="Number" Binding="{Binding Number}" />
</DataGrid.Columns>
</DataGrid>
<DataGrid attached:DataGridHelpers.UseCustomSort="True" ItemsSource="{Binding Items}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Item.Item1.Item2.TextNumber}" Header="Code"
attached:DataGridHelpers.CustomSorterType="{x:Type comparers:StrLogicalComparer}" />
</DataGrid.Columns>
</DataGrid>