I was trying to learn prism, but I am unable to get a very basic example working. I have a Shell which has a single region. I am trying to load a view from module into a shell's region but the shell shows a blank window. I am just not able to figure out why the view is not loaded into the shell's region. Here are the code files.
BootStrapper:
public class Bootstrapper : MefBootstrapper {
protected override DependencyObject CreateShell() {
Window shell = new MainWindow();
Application.Current.MainWindow = shell;
return shell;
}
protected override IModuleCatalog CreateModuleCatalog() {
return new ConfigurationModuleCatalog();
}
}
Shell:
<Window x:Class="MVVMPractice.MainWindow">
<StackPanel x:Name="LayoutRoot" Background="White">
<ContentControl prism:RegionManager.RegionName="MainRegion" />
</StackPanel>
</Window>
Module:
[ModuleExport(typeof(CoreModule))]
public class CoreModule : IModule {
[Import]
public IRegionManager RegionManager { get; set; }
public void Initialize() {
var view = new WelcomeView();
RegionManager.AddToRegion("MainRegion", view);
}
}
View To Load in Region:
<UserControl x:Class="MVVMPractice.Modules.Core.WelcomeView">
<Grid Background="Red">
<TextBlock Text="Hello Prism!" FontSize="20" />
</Grid>
</UserControl>
The above view should show up in the shell, but it doesn't. Any ideas why shell's region does not show the above view ?
EDIT: The Module is configured through the App.config file as given below.
App.config
<configuration>
<configSections>
<section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection,
Microsoft.Practices.Prism"/>
</configSections>
<modules>
<module assemblyFile="MVVMPractice.Modules.Core.dll"
moduleType="MVVMPractice.Modules.Core.CoreModule, MVVMPractice.Modules.Core.CoreModule,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
moduleName="CoreModule"
startupLoaded="true" />
</modules>
</configuration>
RegionManager.RegisterViewWithRegion("MainRegion", view)
, instead of adding the view to the region. It seems to me that it only adds it to the region and not show it. - Rik van den Berg