1

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

Louis Kottmann
  • 16,268
  • 4
  • 64
  • 88
  • Can you tell us what is the type of oneOfMyUserControls? – Ucodia Sep 14 '11 at 13:46
  • It's a UserControl, I have over 40 different of those... I resolve the right object somewhere else in the code, but I don't believe it is relevant to the problem, they are all UserControls and they work properly outside this scenario. – Louis Kottmann Sep 14 '11 at 13:48
  • I'm trying inspector right now, i'll let you know – Louis Kottmann Sep 14 '11 at 14:01
  • In the second example you give it is totally normal that it won't work because you are adding a view to a ContentControl and the default RegionAdapter for ContentControl provided by Prism is a single active region which accepts only one active view at a time (see SingleActiveRegion class). Makes total sense for a ContentControl. You probably do not want to put your hands in the dirt but learning how RegionAdapter works will give you a much better understanding of Prism region feature. – Ucodia Sep 14 '11 at 15:06
  • Do you have a link to the DocumentPaneRegionAdapter so I can have a look at it? – Ucodia Sep 14 '11 at 15:09
  • I found the solution, I merged ideas from the link in my question with http://blog.raffaeu.com/archive/2010/07/04/wpf-and-prism-tab-region-adapter-part-02.aspx and now it works. Well, I still have to figure out a way to put the same UserControl multiple times in the DocumentPane, but I believe that's outside the boundaries of this question. Your help in pointing me out was great, thanks. – Louis Kottmann Sep 14 '11 at 15:52
  • It is probably out of this question but I might have an answer. Do you retrieve oneOfMyUserControls instance through ServiceLocator or using the Mef/UnityContainer? Because if it is the case, you have to mark your view with an attribute specifying that this instance will not be shared. For example with MEF you would decorate your view with: [PartCreationPolicy(CreationPolicy.NonShared)]. This way it will create a new instance everytime you import it so you won't have the same instance in your container anymore. – Ucodia Sep 15 '11 at 08:53
  • Well, my specifics don't allow me to do that. Instead, i have a custom attribute that specifies custom actions behaviors, and depending on that some views are singletons, some are not. – Louis Kottmann Sep 15 '11 at 09:36
  • Ok. What is sure is that Prism regions wont allow you to add a singleton view more than once. – Ucodia Sep 15 '11 at 11:35
  • I confirm, i had to battle with it :p – Louis Kottmann Sep 15 '11 at 12:21

1 Answers1

2

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.

Ucodia
  • 7,410
  • 11
  • 47
  • 81