【发布时间】:2018-02-13 08:27:46
【问题描述】:
我在 CollectionViewSource 中有一些组件对象需要排序,这些对象都有自定义类型。分组是在类型上完成的,组件按它们的名称排序。我现在需要做的是对组件类型的分组进行排序但是我需要根据外部源对这些组件类型进行排序,所以对象看起来有点像这样:
public class ComponentType
{
public Guid Identification
{
get;
}
}
public class Component
{
public string Name
{
get;
}
public ComponentType Type
{
get;
}
}
集合视图是这样创建的:
this.ComponentCollection = new CollectionViewSource();
this.ComponentCollection.Source = this.Components;
this.ComponentCollection.GroupDescriptions.Clear();
this.ComponentCollection.GroupDescriptions.Add(new PropertyGroupDescription("ComponentType"));
this.ComponentCollection.SortDescriptions.Clear();
this.ComponentCollection.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
this.ComponentCollection.Filter += this.FilterComponent;
this.ComponentCollection.View.Refresh();
RaisePropertyChanged(() => this.ComponentCollection);
我在创建 CollectionViewSource 的同一个类中也有以下字典,如下所示:
public Dictionary<Guid, int> ComponentTypePositions
其中key是组件类型的标识,int是应该先出现的类型的位置。
不能将位置作为属性放在 ComponentType 或 Component 类中,它需要是一个单独的列表。
如何根据 ComponentTypePositions 字典中对应的编号对分组进行排序?
【问题讨论】:
标签: c# sorting collectionviewsource