2

I have a Silverlight Toolkit datagrid where one column shows textual representation of a numeric value. I would like to sort on the column's underlying numeric value but present the text data to the user. Values in the grid column are in a format such as:

  • A Category (200-300)
  • Some Category (100-200)
  • Yet Another Category (300-400)

As these values are textual the grid is correctly sorting on the text, however I have a custom Comparer which can already sort these by the numeric categories and would like to plug it into the grid.

The data-object that the grid cell is binding to only has the textual representation (and no way of easily adding the numeric value). Therefore, SortMemberPath= won't work in this case.

Is it possible to inject a custom comparer for a single grid column and sort on that? Or perhaps implement a CollectionViewSource with custom comparer? Remember this is Silverlight, not WPF so some fields/properties/classes are missing when compared to WPF.

4

1 回答 1

1

The simplest way I feel to achieve this is to add two properties to entity that you are binding to grid one will be the text and the other can be numeric and binding only one to column of grid and other you can use in SortMemberPath. If not two properties you want to keep in entity then, you can keep Numeric only and use converter to convert it into text and SortMemberPath=NumericPropertyName.

于 2012-05-28T06:48:34.700 回答