PRISM RegionManager not adding regions of the Shell
I have a Main WPF application and other modules and I am using PRISM to host the view of the modules in different regions defined in my Shell. This works fine for me. I now have a requirement to set my Main application as class library and invoke it from another Window Application. This new Window application has a Main function with the following code.
[System.STAThreadAttribute()]
public static void Main()
{
Application app = new Application();
IStartupUI start = new StartupUI();
start.StartUserInterface();
app.Run();
}
The start.StartUserInterface basically calls the function in the dll which has following code
开发者_运维技巧 ABCBootStrapper bootstrapper = new ABCBootStrapper ();
bootstrapper.Run();
The same piece of code was earlier called in OnStartup when the Dll itself was the main application.
Now with this change the Shell does not show any view. On debugging I found that the RegionManager does not recognize any regions that are defined in the Shell. Basically number of regions registered with RegionManager are 0. All the regions defined in the shell are ContentControl.
My problem seemed to have been solved by doing the following:
I made the class which contains the Main function derive from System.Windows.Application and instead of directly creating the instance of Application I created the instance of the class and I put the code for starting the user interface into the OnStartup event handler.
class Test : System.Windows.Application
{
[System.STAThreadAttribute()]
public static void Main()
{
Test app = new Test();
app.Startup += new StartupEventHandler(app_Startup);
app.Run();
}
static void app_Startup(object sender, StartupEventArgs e)
{
IStartupUI start = new StartupUI();
start.StartUserInterface();
}
}
精彩评论