在复合WPF(Prism)中,IRegion.Add和IRegionManager.RegisterViewWithRegion有什么区别?
在Composite WPF (Prism)中,向IRegionManger集合添加模块时,使用IRegion.Add和IRegionManager.RegisterViewWithRegion?
IRegion.Add
public void Initialize()
{
_regionManager.Regions["MainRegion"].Add( new ModuleAView() );
}
IRegionManager.RegisterViewWithRegion
public void Initialize()
{
_regionManager.RegisterViewWithRegion( "MainRegion", typeof( ModuleAView ) );
}
In Composite WPF (Prism), when adding modules to the IRegionManger collection, what is the difference between using IRegion.Add and IRegionManager.RegisterViewWithRegion?
IRegion.Add
public void Initialize()
{
_regionManager.Regions["MainRegion"].Add( new ModuleAView() );
}
IRegionManager.RegisterViewWithRegion
public void Initialize()
{
_regionManager.RegisterViewWithRegion( "MainRegion", typeof( ModuleAView ) );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
区别在于谁负责创建视图。在 IRegion.Add 场景(也称为视图注入)中,您负责预先实例化视图。在使用
RegisterViewWithRegion
(也称为视图发现)的另一个场景中,区域管理器实例化视图本身。由于一些技术原因,您可能想要选择其中之一。例如,
相关文档是:
对于视图组合(包括视图注入与视图发现以及视图优先或视图呈现者优先方法的讨论):
http://msdn.microsoft.com/en-us/library/dd458944.aspx
还有一个非常方便的“何时使用每个”部分。这是文档的摘录:
希望这有帮助。
The difference is who is responsible for creating the view. In the
IRegion.Add
scenario (also called View Injection) you are responsible for instantiating the view beforehand. In the other scenario withRegisterViewWithRegion
(also called View Discovery), the region manager instantiates the view itself.There are some technical reasons you would want to do one or the other. For example
The relevant documenation is:
For View Composition (including View Injection vs. View Discovery and discussions of View-First or View-Presenter-First approaches):
http://msdn.microsoft.com/en-us/library/dd458944.aspx
There's also a really handy "when to use each" section. Here's the excerpt from the docs:
Hope this helps.
RegisterViewWithRegion 引发 OnContentRegistered 事件,但当然情况可能并非如此,具体取决于您的 DI
RegisterViewWithRegion raises the OnContentRegistered event, but of course that could not be the case depending on your DI