How to get RegionManager in bootstrap in Prism

I am encountering a problem using the method

this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView)); 

If I write the above code in the boot tape in some way. This does not work because I cannot get the regionmanager object from the code

 IRegionManager manager = this.Container.Resolve<IRegionManager>(); 

The above exception throws an exception "Exception message: current build operation (Build Key [Microsoft.Practices.Composite.Regions.IRegionManager, null]) failed: the current type, Microsoft.Practices.Composite.Regions. IRegionManager, is an interface and can't be constructed. Are you missing a type mapping? "

But on working on the code, I put it in some ViewModel and injected IRegionManager into it.

as

  public HeaderControlViewModel(IEventAggregator aggregator, IRegionManager regionManager) : base(aggregator) { this.regionManager = regionManager; this.regionManager.RegisterViewWithRegion("TextRegion", typeof(TextView)); } 

But I do not want to do this. I want everything to be configured with only the bootloader.

Please tell me why bootstrapper cannot get a RegionManager object? How can I solve this problem?

Thank you very much in advance...

+4
source share
1 answer

// ... App.xaml.cs

  public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Bootstrapper bs = new Bootstrapper(); bs.Run(); bs.ShowDefault(); } } 

// ... Bootstrapper.cs

 public void ShowDefault() { RegionManager.GetRegionManager(Application.Current.MainWindow) .RequestNavigate("MainRegion", "ViewA"); } 

// ...

-one
source

Source: https://habr.com/ru/post/1392197/


All Articles