所以,WPF不支持的意见CompositeCollections标准排序或筛选的行为,因此这将是解决tihs问题的最佳实践。
So WPF doesn't support standard sorting or filtering behavior for views of CompositeCollections, so what would be a best practice for solving tihs problem.
有不同类型的两个或多个对象的集合。你想将它们组合成一个单一的排序和筛选的集合(withing不必手动实现排序或筛选)。
There are two or more object collections of different types. You want to combine them into a single sortable and filterable collection (withing having to manually implement sort or filter).
一,我所考虑的方法是创建只有几个核心属性,包括那些我希望集合排序的,每种类型的对象实例的新对象的集合。
One of the approaches I've considered is to create a new object collection with only a few core properties, including the ones that I would want the collection sorted on, and an object instance of each type.
class MyCompositeObject
{
enum ObjectType;
DateTime CreatedDate;
string SomeAttribute;
myObjectType1 Obj1;
myObjectType2 Obj2;
{
class MyCompositeObjects : List<MyCompositeObject> { }
然后通过我的两个对象collectiosn循环来构建新的复合集合。显然,这是一个有点蛮力方法,但是它的工作。我会得到我的新组合对象集合中的所有默认视图排序和过滤行为,我能够把数据模板上显示我的列表项正确地取决于哪种类型的实际存储在该复合材料项目。
And then loop through my two object collectiosn to build the new composite collection. Obviously this is a bit of a brute force method, but it would work. I'd get all the default view sorting and filtering behavior on my new composite object collection, and I'd be able to put a data template on it to display my list items properly depending on which type is actually stored in that composite item.
有什么建议,在那里为一个更优雅的方式做这个?
What suggestions are there for doing this in a more elegant way?
推荐答案
更新:我发现了一个更优雅的解决方案:
Update: I found a much more elegant solution:
class MyCompositeObject
{
DateTime CreatedDate;
string SomeAttribute;
Object Obj1;
{
class MyCompositeObjects : List<MyCompositeObject> { }
我发现,由于反射,存储在OBJ1的具体类型得到解决在运行时和类型特定的DataTemplate施加按预期!
I found that due to reflection, the specific type stored in Obj1 is resolved at runtime and the type specific DataTemplate is applied as expected!
相关推荐
最新文章