如何在Prism/MEF中的ItemsControl中对视图进行排序? [英] How to sort views in an ItemsControl in Prism / MEF?
问题描述
我使用棱镜v4和MEF加载模块.我的模块包含少数视图(MVVM),这些视图由MEF自动加载到ItemsControl/NavigationRegion中.
I use prism v4 and MEF to load my modules. My modules contain a handful of views (MVVM) which are loaded in a ItemsControl/NavigationRegion automatically by MEF.
这很好用,所有项目都显示在ItemControl中.但是我不喜欢它们显示的顺序.一个模块可能包含多个项目,因此仅靠更改模块加载顺序是不够的.
This works nicely, all items show up in the ItemControl. But I don't like the order in which they show. One module might contain several of the items, so changing the module load order is not enough by itself.
如何在ItemsControl中对不同的视图进行排序?有什么办法可以按某种属性对它们进行排序吗?
How can I sort the different views in the ItemsControl? Is there any way to sort them by some property?
由于使用了StockTraderRI示例中的属性,因此我使用了棱镜V4,MEF和勘探.
I use prism V4, MEF and exploration due to attributes like in the StockTraderRI example.
推荐答案
这实际上已植入Prism4.只需将ViewSortHintAttribute应用于您的视图即可:
This is actually baked into Prism4. Just apply the ViewSortHintAttribute to your views:
[ViewSortHint("100")]
class FirstView : UserControl { }
[ViewSortHint("200")]
class SecondView : UserControl { }
区域上的默认排序比较器将选择此属性并相应地对视图进行排序.您可以将任何字符串放入属性中,但是我倾向于使用中等大小的数字,这样我就可以轻松地在现有视图之间放置新视图.
The default sort comparer on the regions will pick up this attribute and sort the views accordingly. You can put any string into the attribute but I tend to use medium sized numbers that allow me to easily put a new view in between existing ones.
这篇关于如何在Prism/MEF中的ItemsControl中对视图进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!