0
votes

I have existing WPF application. In this application, I have main TabControl and under this TabControl I have multiple Tabs.

I want to apply Prism architecture only in one tab. I want to create Shell as one tab.

Is it possible to apply? If yes, how can I hook BootStrapper for that particular tab. In this case, I want to load this tab on demand. When user clicks this tab. I want to load all UI elements through BootStrapper and then I want to run the Shell

Can I use UserControl_Loaded event to trigger my bootstrapper? If yes, how can I instantiate bootstrapper?

I hope question is comprehensible.

2

2 Answers

1
votes

It works, but you have to do some stuff by hand (especially if you want modules to work). Follow these steps to get your thing working:

First create a usual Prism project with Bootstrapper, Shell and so on .. Then get the UserControl with the regions that way, when you want to display it:

ServiceLocator.Current.GetInstance<TestUc>();

In the constructor of the UserControl let the ServiceLocator give you the RegionManager as parameter and do the following after InitializeComponent()

RegionManager.SetRegionManager(this, regionManager);
RegionManager.UpdateRegions();

This sets the attatched dependency property to be used as RegionManager.RegionName="..." in Xaml. And now you can either set the regions via RegionManager right now or pull up the whole bunch of Prism infrastructure to load some modules from config. Suppose you want to go the hard way. Past this code at the bottom of your UserControl´s constructor, and modules will be loaded from App.config:

var catalog = new ConfigurationModuleCatalog
{
    Store = new ConfigurationStore()
};

var logger = new TextLogger();
var moduleInitializer = new ModuleInitializer(ServiceLocator.Current, logger);
var moduleManager = new ModuleManager(moduleInitializer, catalog, logger);

moduleManager.Run();

I uploaded a little test project for you on my ftp server: http://compositedevtec.tk/upload/prismTest.zip

0
votes

I'm not sure this would work how you would expect as the bootstrapper is used to fire up the shell. You could accomplish this by having your application be the shell and go through the process of firing up the bootstrapper with the shell set to the main application. The main application would then be your WPF app, but somewhere inside the app you define your one region to work with.

I do not think, however, that just adding a region to a tab item and then firing up your application would work. The bootstrapper needs to be the starting target in order for all the IoC magic to occur.

Short answer: Yes, with caveats to how you write your shell.