AvalonDock 的 DocumentPane 和 DockingPane 的 Prism2 区域适配器?
有人有关于如何为 AvalonDock 的 DocumentPane 和 DockingPane 创建区域适配器的示例代码吗?
Does anyone have sample code on how to create a Region Adapter for AvalonDock's DocumentPane and DockingPane?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Markus Raufer 已将两个区域适配器添加到 CompositeWpfContrib 项目,网址为 CodePlex 同时支持
DocumentPane
和DockingPane
。The Markus Raufer has added two region adapters to the CompositeWpfContrib project at CodePlex that supports both
DocumentPane
andDockingPane
.我已经使用了 Raffaeu Bermuda 片段支持 Avalon tab 区域适配器,但发现有一些问题没有解决:
1- 它不支持 Activating a a certain view (aka - tab - DockableContent),所以代码
Region .Activate(object view)
将不起作用。2- 默认情况下,该区域中的所有选项卡均处于活动状态。 所以
Region.ActiveViews
集合默认包含所有视图,这并不理想,因为有时我需要验证视图是否处于活动状态(您可以想象工具栏区域上的保存按钮仅在当前活动视图 = 选项卡(在我们的例子中)上执行 SaveCommand)3- 关闭的视图实际上并未关闭,只是隐藏。 即使您在添加 newDockableContent 时设置了
HideOnClose = true
,它仍然不会从Region.Views
集合中删除。 这可能会导致内存泄漏问题。4-如果您之前在窗格中添加了 DockableContent,它们将不会同步并添加到 Region.Views 集合中。
下面是我现在使用的代码,它只是 PRISM 源代码中的选择器适配器和选择器同步行为的一个小调整:
AvalonRegionAdapter 类:
AvalonDocumentSyncBehavior 行为代码:
在引导程序上配置适配器的代码
然后您需要 TabModel 和 TabViewModel,如 Raffaeu Bermuda
和一个作为基类的 TabViewModel:
如果您需要进一步的帮助,请告诉我,我将在不久的将来发布一篇博客。
I have used Raffaeu Bermuda snippets to support Avalon tab region adapter, but found that there is some issues are not solved:
1- It does not support Activating a a certain view (aka - tab - DockableContent), so the code
Region.Activate(object view)
will not work.2- All the Tabs are active by default in the region. So
Region.ActiveViews
collection by default has all the views, this is not ideal, as sometimes I needed to verify if a view is active or not (you could imagine a save button on a tool bar region that executes a SaveCommand only on the current active view = tab in our case)3- Closed views doesn't actually get closed, only hidden. Even if you set the
HideOnClose = true
when adding the newDockableContent, it is still not removed fromRegion.Views
collection. This could lead to memory leaks issues.4- If you have a previously added DockableContent in the Pane, they will not get synchronized and added to the Region.Views collection.
So here are the code I am using now, it is just a small tweak from the Selector Adapter and Selector Sync Behavior found in PRISM source code:
AvalonRegionAdapter Class:
AvalonDocumentSyncBehavior Behavior Code:
Code on bootstrapper to configure the Adapter
Then you need the TabModel and the TabViewModel as fromRaffaeu Bermuda
And a TabViewModel acting as a base class:
Let me know if you need further help, I will post a blog this in the near future.
由于 Avalon DocumentPane 和 DockingPane 都基于 System.Windows.Controls.Primitives.Selector,因此您可以使用 Prism 中的默认 SelectorRegionAdapter。
只需将您的控件基于
主 Shell.xmal 上的 DockableContent,设置可停靠窗格中的区域,
然后当您初始化控件的演示器时,它将显示在扩展坞中。
Since the Avalon DocumentPane and DockingPane are both based on the System.Windows.Controls.Primitives.Selector you can use the default SelectorRegionAdapter in Prism.
Just base your control on DockableContent
on your main Shell.xmal set the regions in the dockablepane
then when you initialize your presenter for your control it will get displayed in the dock.
我的建议是查看 Prism 源中的 Microsoft.Practices.Composite.Presentation.Regions。 具体来说,查看 ItemsControlRegionAdapter 并将其用作模板。 请记住继承自 RegionAdapterBase<>:
并覆盖引导程序中的ConfigureRegionAdapterMappings()。 那看起来像:
My advice would be to look in Microsoft.Practices.Composite.Presentation.Regions in the Prism source. Specifically, take a look at the ItemsControlRegionAdapter and use it as a template. Remember to inherit from RegionAdapterBase<>:
and to override ConfigureRegionAdapterMappings() in the bootstrapper. That would look something like: