如何在 Prism 中获得对某个区域的控制
有谁知道如何获得与 Prism 中某个区域关联的控件。
例如,如果我有以下代码来注册区域
RegionManager.SetRegionName(Outlook.navigationContainer, "navigationContainer");
如何通过名称“navigationContainer”获取 Outlook.navigationContainer 控件?
谢谢大家。
Does anyone know how to get the control associated with a region in Prism.
For example, if I have the following code to register a region
RegionManager.SetRegionName(Outlook.navigationContainer, "navigationContainer");
How can I get the control Outlook.navigationContainer via the name "navigationContainer"?
Thanks heaps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
回答您的问题:
您可能可以创建一些使用自定义区域行为来跟踪此情况的东西。 RegionBehaviors 的详细信息可以在这里找到: http://msdn.microsoft.com/ en-us/library/dd458944.aspx
您只需创建一个字典来跟踪区域名称和关联的控件,因为您可以从区域行为访问这两者。
如果您需要在将视图添加到区域时访问该控件,则您可能需要使用区域适配器来实现此目的(详细信息请参见上面的同一链接)。
但是,我150%同意肯特的观点,我闻到你正在做一些你不应该做的事情。如果您正在尝试自定义布局或创建动画等,您应该真正关注不需要打破区域为您提供的抽象的策略。
像带有数据触发器的样式这样简单的东西可以为您提供您正在寻找的内容,并且不会强迫您从将视图添加到该区域的代码中了解太多有关容器的信息。
To answer your question:
You could likely create something that tracks this using a custom Region Behavior. Details of RegionBehaviors can be found here: http://msdn.microsoft.com/en-us/library/dd458944.aspx
You'd simply create a dictionary that tracked the region name and the associated control, since you have access to both from a Region Behavior.
If you need access to the control at the time a view is being added to the region, you would want to use a Region Adapter for this purpose (details at the same link above).
However, I agree 150% with Kent here that I smell you are doing something you should not. If you are trying to customize the layout or create animations / etc you should really focus on a strategy that doesn't require you to break the abstraction that Regions give you.
Something as simple as a style w/ data triggers could give you what you are looking for and wouldn't force you to know too much about the container from the code that adds the views to the region.
区域应该从您那里抽象出区域控制的细节。为什么需要获得控制权?
Regions are supposed to abstract away the specifics of the region control from you. Why do you need to get the control?
我认为您无法通过区域名称轻松获得关联的控件。
SetRegionName 方法仅设置指定控件上的“RegionNameProperty”DependencyProperty。您唯一能做的就是在获得控制权后取回名称。
I don't think you can easily get the associated control via the region name.
The SetRegionName method only sets the "RegionNameProperty" DependencyProperty on the specified control. The only thing you can do is to get the name back when you have the control.
想一想,
如果您想更改注入区域的模块的属性,最好的方法是根据您的情况使用路由事件或路由命令。
我这样做的方式是,当模块初始化时,我订阅需要更改的属性的事件。如果系统中的任何其他模块需要更改该属性,我只需触发该事件。
我希望这能让你走上正轨。
问候
科尼利厄斯·克鲁格
ThinkAbout,
If you want to change a property on a module that is injected into a region, the best way to do it is to use either a routed Event or a routed Command depending on your situation.
The way I do it is, when the module is initialized I subscribe to events for for the properties that need to be changed. If any other module in the system need to change that property, I just fire the event.
I hope that puts you on the right track.
Regards
Cornelius Kruger