简体   繁体   English

如何为可用于Silverlight DataGrid列排序的模型上的特定属性指定IComparer

[英]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. 我有一个Silverlight数据网格,其中的列绑定设置为模型上的字符串属性。 These strings are alphanumeric, so I have created a custom IComparer to sort them appropriately. 这些字符串是字母数字,因此我创建了一个自定义IComparer来对它们进行适当排序。 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. 就像属性波纹管一样,但是在您的情况下,您应该使用ICompare返回。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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