gpt4 book ai didi

prism - 在 Composite WPF (Prism) 中,IRegion.Add 和 IRegionManager.RegisterViewWithRegion 有什么区别?

转载 作者:行者123 更新时间:2023-12-03 22:22:48 28 4
gpt4 key购买 nike

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 ) );
}

最佳答案

区别在于谁负责创建 View 。在 IRegion.Add场景(也称为 View 注入(inject))您负责事先实例化 View 。在 RegisterViewWithRegion 的另一种情况下(也称为 View 发现),区域管理器实例化 View 本身。

有一些技术原因你会想要做一个或另一个。例如

  • 您有一种更复杂的创建 View 的方法(也许您想创建 View 及其 ViewModel 并通过自己设置 DataContext 属性将它们结合起来),您需要使用 View Injection
  • 如果您利用 Region Scopes,您将被迫使用 View Injection。

  • 相关文件为:
    对于 View 组合(包括 View 注入(inject)与 View 发现以及 View 优先或 View 呈现者优先方法的讨论):
    http://msdn.microsoft.com/en-us/library/dd458944.aspx

    还有一个非常方便的“何时使用每个”部分。这是文档的摘录:

    • Explicit or programmatic control over when a view is created and displayed, or when you need to remove a view from a region, for example, as a result of application logic.
    • To display multiple instances of the same views into a region, where each view instance is bound to different data.
    • To control which instance of a region a view is added (for example, if you want to add customer detail view to a specific customer detail region). Note that this scenario requires scoped regions described later in this topic.


    希望这可以帮助。

    关于prism - 在 Composite WPF (Prism) 中,IRegion.Add 和 IRegionManager.RegisterViewWithRegion 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1421984/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com