a bit new to Prismv4 and MEF.
I went through the QuickStarts and tried to combine two of them together, but I can't seem to get it working.
First, I got a Bootstrapper to load the Shell Window.
public sealed class ClientBootstrapper : MefBootstrapper
{
protected override void ConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
//Add this assembly to export ModuleTracker (Shell is in this Assembly).
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
}
protected override DependencyObject CreateShell()
{
return Container.GetExportedValue<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (Window)Shell;
Application.Current.MainWindow.Show();
}
}
This worked fine. The Shell window was shown and a nice Hello World message appeared. Then I tried to create a Region inside the Shell window so I can load a View into that region. I haven't even gotten this to work to even look at moving it to an outside assembly.
[ModuleExport(typeof(HelloWorldModule), InitializationMode = InitializationMode.OnDemand)]
public class HelloWorldModule : IModule
{
[Import(AllowRecomposition = true)]
private IRegionViewRegistry regionViewRegistry;
[ImportingConstructor()]
public HelloWorldModule(IRegionViewRegistry registry)
{
this.regionViewRegistry = registry;
}
public void Initialize()
{
regionViewRegistry.RegisterViewWithRegion("PrimaryRegion", typeof(Views.HelloWorldView));
}
}
The HelloWorld view (just a simple UserControl that contains a TextBlock) is not being loaded into the region! I guess I'm a bit lost here on how to load in my regions.
You can try this and it works for me, the Module class as follows:
[ModuleExport(typeof(HelloWorldModule))]
public class HelloWorldModule : IModule
{
[Import]
private IRegionManager regionManager;
public void Initialize()
{
Uri viewNav = new Uri("HelloWorldView", UriKind.Relative);
regionManager.RequestNavigate("PrimaryRegion", viewNav);
}
}
The View class as follows:
[Export("HelloWorldView")]
[PartCreationPolicy(CreationPolicy.Shared)]
public partial class HelloWorldView : UserControl
{
public HelloWorldView()
{
InitializeComponent();
}
}
The xaml in HelloWorldView
<UserControl x:Class="HelloWorldModule.HelloWorldView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock>Hello World</TextBlock>
</Grid>
</UserControl>
You will need
protected override void ConfigureAggregateCatalog()
{
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(HelloWorldModule.HelloWorldModule).Assembly));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With