开发者

Dynamically create tab and inject a view in it

I use AvalonDock to have a vs-like docking style, and I use prism to inject views in my application.

Basically the user will have a panel on the side with one button per view loadable, and each time he presses one, I want to create a new tab on my AvalonDock's DocumentPane, and inject the right view in it.

Now I was under the impression that prism is good for this kind of scenario, but I can'f figure it out.

Also, I stumbled accross DocumentPane and DockablePane region adapters by Markus Raufer, have added it to my project and registered the mappings in the bootstrapper.

This allows me to compile the solution (so I'm guessing I'm getting close).

So far, I do this:

In my Shell I have a place with:

<avadock:DocumentPane avadock:ResizingPanel.ResizeWidth="500" Background="Transparent"
                      prism:RegionManager.RegionName="{x:Static inf:RegionNames.MainTabControlRegion}">
</avadock:DocumentPane>

In my code-behind, after Bootstrapping etc, I have a place that does:

m_RegionManager.Regions[RegionNames.MainTabControlRegion].Add(oneOfMyUserControls);

Executing this line doesn't show anything more to the user, but if i execute it twice, it will make an error saying a view is already registered (so it did add something!).

Furthermore, when i put a regular ContentControl, mark it with prism:RegionManager.RegionName="{x:Static inf:RegionNames.MainTabControlRegion} then add a UserControl in it the very same way I add it to AvalonDock's DocumentPane, it works. freaky

What am I doing wrong?

Thanks,

开发者_如何学运维

bab.

EDIT:

If define the MainTabControlRegion like this, the first view actually gets added, now id i add another one (different UserControl) it doesn't show it, but WPF Inspector says it's there.

From my point of view, it is indeed adding UserControls to a region, but it doesn't know how to create a new tab for each UserControl I add to the DocumentPane.

Since I'm not specifying anything about that, I'm probably missing a piece of code?

<avadock:DocumentPane avadock:ResizingPanel.ResizeWidth="500" Background="Transparent">
    <avadock:DocumentContent Title="" prism:RegionManager.RegionName="{x:Static inf:RegionNames.MainTabControlRegion}">

    </avadock:DocumentContent>
</avadock:DocumentPane>

I want it to create a new tab each time i add a usercontrol and insert it in there.

EDIT 2: Solution --> Here


This problem can be caused for many reasons.

Or the RegionAdapter is not well suited for the user controls you are trying to add, therefore I would recommend you to have a look at RegionAdapter implementation so you can have a good understanding of how it adapts your view in the region and customize it to fit your needs.

Or the user control you are adding has a particular behavior and is bugging the RegionAdapter when it tries to add your view to the DocumentPane items. Therefore you can customize the RegionAdapter or fix the user control behavior.

Or it is simply a data binding problem. The fact that nothing shows up on first execution is kind of strange. Try to inspect your DocumentPane property Binding with WPF Inspector. It saved my life more than once when dealing with custom RegionAdapters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜