简体   繁体   English

Silverlight DataGridColumn基于内容(而不是基础属性)排序

[英]Silverlight DataGridColumn sorting based on content (and not on underlying property)

I have a DataGrid , where I am displaying some Job data. 我有一个DataGrid ,在其中显示一些Job数据。 One of the field is calculated based on 2 columns. 字段之一是基于2列计算的。

There is a calculated field StaffName that comes from different properties (which are hidden in data grid). 有一个计算得出的字段StaffName来自不同的属性(隐藏在数据网格中)。

I want to sort StaffName based on the content displayed on grid, and not based on underlying property on which Converter is applied. 我想根据显示在网格上的内容而不是根据应用了Converter基础属性对StaffName进行排序。 there are actually multiple underlying properties, and handling sorting of these is complex. 实际上有多个基础属性,处理这些属性的过程很复杂。 The data structure comes from some other assembly which is not aware of any converters/lookups which transform different property into StaffName . 数据结构来自其他一些程序集,该程序集不知道任何将不同的属性转换为StaffName转换器/查找。

How to achieve this? 如何实现呢?

You need to capture the sort event and do the Sort the itemcollection based on your need and Assign the newly sorted collection to the ItemSource . 您需要捕获sort事件并根据需要对itemcollection进行Sort并将新排序的collection分配给ItemSource。 Following Link shows how to sort. 以下链接显示了如何排序。 Check the sample 检查样品

In the example it is normal sorting, at Places LINQ queries used you need to write your own LINQ query involving the fields you want to use in the orderby clause 在该示例中,这是正常排序,在使用Places LINQ查询时,您需要编写自己的LINQ查询,其中涉及要在orderby子句中使用的字段

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

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