...
First of all, you must make available the region manager on the instance of ServiceLocator. A Prism based application uses MEF or Unity as primary IoC contanier. Therefore, you must synchronize this container with the Catel one, overriding the ConfigureContainer method of the application Bootstrapper class, using the following code:
Code Block |
---|
protected override void ConfigureContainer() { base.ConfigureContainer(); if (ServiceLocator.Instance.IsExternalContainerSupported(this.Container)) { ServiceLocator.Instance.RegisterExternalContainer(this.Container); } } |
but if you use ServiceLocator primary IoC contanier, and your Bootstrapper class inherits from BootstrapperBase the region manager is actually available and you don't have to write the synchronization container code.
...
Code Block |
---|
var viewModel = new EmployeeViewModel(); var dependencyResolver = this.GetDependencyResolver(); var uiVisualizerService = GetService<IUIVisualizerService>dependencyResolver.Resolve<IUIVisualizerService>(); uiVisualizerService.Activate(viewModel, "MainRegion"); |
...
Actually you are able to inject views (referencing it's view models) in any window. Just like the previous example but in combination with the experimental extension method Show:
Code Block |
---|
var dependencyResolver = this.GetDependencyResolver(); var uiVisualizerService = GetService<IUIVisualizerService>dependencyResolver.Resolve<IUIVisualizerService>(); var windowViewModel = new WindowWithRegionViewModel(); uiVisualizerService.Show(windowViewModel, () => { uiVisualizerService.Activate(new EmployeeViewModel(), windowViewModel, "WindowMainRegion") }); |
...
Note |
---|
User interface composition feature that comes with Prism extension is only available in NET40, NET45 , Silverlight 4 and Silverlight 5 |