简体   繁体   中英

How to specify an IComparer for a particular property on a model that can be used for Silverlight DataGrid column sorting

I have a Silverlight datagrid with a column who's binding is set to a string property on the model. These strings are alphanumeric, so I have created a custom IComparer to sort them appropriately. My question is how can I force the grid to use this custom comparer when sorting by this column?

One of my ideas was perhaps there is some attribute that can be applied on the model's string property that I am binding to, that would explicitly specify the comparer to use when comparing this value with another string?

如果将网格绑定到ViewModel,则可以在绑定到View的属性的获取中使用ICompare。

Like the property bellow, but in your case you should return using your ICompare.

private ObservableCollection<ListOfMyClassType> myGridItemSource;
public ObservableCollection<ListOfMyClassType> MyGridItemSource
{
      get { return myGridItemSource; }
      set { myGridItemSource = value; OnPropertyChanged("MyGridItemSource");}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM