I tried to find a way to configure the wpf DataGrid to loop through sortings: {ascending, descending, no sort} when clicked repeatedly.
I wrote this (but did not love it hence this q):
<DataGrid AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding DayOfWeek}" >
<DataGridTextColumn.Header>
<DataGridColumnHeader PreviewMouseLeftButtonDown="DataGridColumnHeaderClick">Day</DataGridColumnHeader>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
<sys:DateTime>1/2/3</sys:DateTime>
<sys:DateTime>1/2/4</sys:DateTime>
<sys:DateTime>1/2/5</sys:DateTime>
</DataGrid>
private void DataGridColumnHeaderClick(object sender, RoutedEventArgs e)
{
var header = (DataGridColumnHeader) sender;
if (header.SortDirection == ListSortDirection.Descending)
{
header.Column.SortDirection = null;
e.Handled = true;
}
}
Is there a way to configure the DataGrid to do this without hacking an eventhandler?