【发布时间】:2021-12-13 06:27:52
【问题描述】:
我按照How to: Group, sort and filter data in the DataGrid Control 的示例在 UWP DataGrid 中实现了排序
列排序事件使用数据列标题中的 Tag 来运行特定的 Linq 查询,例如 Tag=“Country”。
我假设的数据网格有 3 个字段“Country”、“Name”、“Height”,因此为了对所有 3 个字段添加排序,我需要复制逻辑并仅使用“orderby 字段”查询每个字段”与众不同。有没有更好的解决方案?
if (e.Column.Tag.ToString() == "Country")
{
mydg.ItemsSource = new ObservableCollection<Mountain>(
from item in myData
orderby item.Country ascending
select item);
}
【问题讨论】:
-
如前所述,SO上有很多实现,mine also