Prism for Silverlight:如何在区域内以特定顺序维护视图 [英] Prism for Silverlight: How to maintain views in a specific order inside a region

查看:13
本文介绍了Prism for Silverlight:如何在区域内以特定顺序维护视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 SL 创建某种导航面板"(实际上是一个 ItemControl)并使用区域来允许每个模块将其链接添加到面板.

I am creating sort of a "Navigation panel" (which is actually an ItemControl) for SL and using Regions to allow each module to add his link to the panel.

问题是模块加载不一致,因此面板中的链接顺序可以根据模块加载顺序发生变化.

Problem is that modules loading is inconsistent and thus order of links in the panel can change according to modules loading order.

限制模块顺序是不可能的.

Restricting the modules order is out of the question.

另外一个可行的方案是将region的ViewsCollection绑定到ItemControl上的顺序,问题是ViewCollection非常有限,所以排序比较困难.

Other feasible option is the order the region's Views Collection that is binded to the ItemControl, the problem is that ViewCollection is very limited, so ordering it is pretty hard.

我错过了一个选项,你有什么想法吗?

Did I miss an option, do you have an idea?

谢谢爱丽儿

推荐答案

在 Prism4 中,您只需将 ViewSortHintAttribute 应用于您的视图:

In Prism4 you 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 for Silverlight:如何在区域内以特定顺序维护视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆