wpfsortingdatagridprotobuf-net

WPF DataGrid not sorting Google.Protobuf.WellKnownTypes.Timestamp column


I have a DataGrid with auto-generated columns and data context bound to a protobuf class. The protobuf class is auto-generated and one of its properties is of type Timestamp. Others are just plain strings. The problem is that I can't sort by the Timestamp column.

Visually nothing happens (not even the sorting arrow) and in the XAML Binding Failures window I get the following error:

Cannot sort by 'Timestamp' InvalidOperationException:'System.InvalidOperationException: Failed to compare two elements in the array.

Should I handle the 'Sorting' event and do custom sort, or is there other way to do it?


Solution

  • It looks like Timestamp does not implement IComparable<Timestamp> or IComparable (citation), so if you want to sort this you'll either need to supply your own IComparer<Timestamp>, or sort it manually.