Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello everybody,

I have tried to find an answer for the following scenario but have failed to come up with an answer.
This may well be due to me, by my own admission, not yet having fully grasped the whole Prism concept.
In my defense, I started looking into Prism only two days ago, so please be gentle ;)

After reading numerous literature I have the following setup:

1. Framework Project
2. Shell Project
3. MainMenu project ( Module)
4. SideMenu project ( Module)
5. StatusBar project ( Module)
6. TestContentA project ( Module)
7. TestContentB project ( Module)

The Framework project contains, amongst other things, event definitions and payloads.

The Shell project has, within the shell.xaml, four regions:
- MainMenuRegion
- SideBarRegion
- StatusBarRegion
- ContentRegion

Every non-Shell project has references to the following Prism assemblies:
- Microsoft.Practices.Prism
- Microsoft.Practices.ServiceLocation
- Microsoft.Practices.Unity

The Shell project has in addition to these assemblies, a reference to:
- Microsoft.Practices.Prism.UnityExtensions

Every project has a reference to the Framework project, but none have a reference to any other project within the solution.

At this point I would like to point out that everthing works as planned!

In the MainMenuView project I have a few MenuItems which have commands in the MainMenuViewModel.
The ViewModel, using the EventAggregator, publishes a couple of Events declared in the Framework project.

In the Shell project, the ShellViewModel subscribes to these events, e.g.:

Using a ContentControl as the control for the "ContentRegion", I can switch between TestContentA and TestContentB with no problems.
(For the moment, both TestContentA and TestContentB are also registered using the .RegisterViewWithRegion method)

What I would like to do is inject TestContentA and TestContentB into a TabControl as a new TabItem, instead of into the ContentControl control.
So shell.xaml now contains a TabControl along with a futher region called "TabRegion".

I have seen a lot of examples like:

IRegion tabRegion = regionManager.Regions["TabRegion"];
var tabView1 = container.Resolve<firsttabview>();
tabRegion.Add(tabView1, "FirstTabView");

I do not have the Container in the ShellViewModel but even if I did have it here, I still cannot refer to the TestContentA view, as this is in another assembly which itself will be found at runtime.
Unlike the samples you can find online, where the view which is to be injected always seems to be in the sample project.

In the Navigate method, if I (for debugging purposes) add the code:

IRegion tabRegion = regionManager.Regions["TabRegion"];

then I can see that tabRegion has a View collection, and in this view I can see both views from TestContentA and TestContentB, but I have no idea how to "grab" them so that I can inject a new instance of the view as a TabItem.

I would appreciate it if someone could point me in the right direction as I'm sure that it can be done.

Thank you for taking the time to read this!
Posted

1 solution

Thanks to a kind used at stackoverflow, I was able to get this working.

I had the shell subscribing to the MainMenu event which wanted to inject either a TestControlA or TestControlB into the TabRegion region, which was wrong.

I removed the subscription from the shell and had the ViewModels for both TestContentA and TestContentB subscribe instead. This is where I added the view to the region.

I hope this helps someone else who may have been thinking along the same lines.

On a side note, I have nothing against somebody giving this question a vote of 1 but please be so kind and state what brought you to act in such a manner. I couldn't see this question being asked elsewhere he and I believe I provided enough information in order to receive assistance and I was most certainly courteous enough.

I thank you all, have a great day!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900