WPF Prism - 是否使用范围区域?
我有一个基于 Prism 2009 年 2 月版本的 WPF 项目,设置为:
Shell 将单个 ContentControl 公开为“MainRegion” 基础设施项目中定义的另一个视图(用户控件)称为 SplitView,它公开了两个附加区域“LeftRegion”和“RightRegion”,也作为 ContentControl。
我的应用程序的某些模块需要在 MainRegion(一个用户控件)中显示其视图,而其他模块则需要在 LeftRegion 和 RightRegion 中显示其视图(以拆分方式显示两个用户控件)。
我尝试过使用作用域区域,假设特定控制器将保存对作用域区域的引用。因此,基本上每个对 SplitView 功能感兴趣的控制器都应该实例化一个新的 SplitView(用户控件)并在 MainRegion 中激活它,同时在新创建的 范围 SplitView 区域的 LeftRegion 和 RightRegion 中激活其两个用户控件。
我使用 MVVM 和视图注入来显示视图。
不用说,这种方法出了严重的问题。
在运行时我收到此异常,“创建名为“LeftRegion”的区域时发生异常。异常是:System.InvalidOperationException:指定的元素已经是另一个元素的逻辑子元素。请先断开它。”
我是否正确地假设每次实例化 SplitView 时 LeftRegion 和 RightRegion 都尝试向主 RegionManager 注册自己?
对于这篇令人困惑/冗长的帖子感到抱歉。有什么建议吗?实现这一目标的最佳实践?
预先感谢,
阿里
I have a WPF project based upon Prism Feb 2009 release set up as:
Shell exposes a single ContentControl as "MainRegion"
Another view (user control) defined in the Infrastructure project called SplitView exposes two additional regions "LeftRegion" and "RightRegion" also as ContentControl.
Some of my application's modules need to display their view in the MainRegion (one user control), while others need to display their views (two user controls in a split fashion) in the LeftRegion and RightRegion.
I have tried using scoped regions, assuming that specific Controllers would hold references to the scoped regions. So basically each controller interested in SplitView functionality should instantiate a new SplitView (user control) and activate it in the MainRegion while activating its two user controls in the LeftRegion and RightRegion of the newly created scoped SplitView regions.
I am using MVVM with View Injection to display the views.
Needless to say, something has gone horrifically wrong with this approach.
At runtime I get this exception, "An exception occurred while creating a region with name 'LeftRegion'. The exception was: System.InvalidOperationException: Specified element is already the logical child of another element. Disconnect it first."
Am I correct at assuming that the LeftRegion and RightRegion are trying to register themselves with the main RegionManager every time I instantiate the SplitView?
Sorry about the confusing/verbose post. Any suggestions? Best practices to achieve this?
Thanks in advance,
Ali
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试将某些内容添加到树中的两个位置时,会发生“指定元素已经是逻辑子元素...”的例外情况,因此我想您的代码中可能存在一些逻辑错误,或者您添加了两次内容。
我通常像这样创建子区域:
然后将任何新内容添加到“m_someThingRegion”中。
The exception of "Specified element is already the logical child..." is what happens when you try to add something to two places in the tree, so I imagine there might be some logical error in your code, or you are adding something twice.
I generally create my sub regions like this:
Then I add any new stuff into the "m_someThingRegion".