I have a DataGrid, with XAML columns as such:
<DataGridTextColumn Header="Time" Binding="{Binding Date, StringFormat='yyyy-MM-dd HH:mm:ss'}" SortMemberPath="Date" SortDirection="Descending" Width="130" CanUserResize="True" />
<DataGridTextColumn Header="Level" Binding="{Binding Level}" Width="60" CanUserResize="True" />
<DataGridTextColumn Header="Source" Binding="{Binding Logger}" Width="150" CanUserResize="True" />
<DataGridTextColumn Header="Message" Binding="{Binding Message}" Width="*" CanUserResize="True" />
I associate this with ObservableCollection<EalsLogEvent>where it EalsLogEvent.Dateis typed DateTime:
public ObservableCollection<EalsLogEvent> LogEvents
{
get
{
return _logEvents;
}
}
In grid view mode, a timer is used to update itself, and everything seems fine with the grid, except when it first loads, when the application starts. Then the column is Timesorted in descending order, but sorted in ascending order.
To get the sort right, I have to double-click the column heading; for the first time, the climbing order is changed, which now matches the contents of the column. A second click on the column heading changes the sort order back to descending, and this time it sorts the contents of the column correctly, i.e. It is decreasing.
LINQ _logEvents, , , . , , LINQ, - .