Hi Agustin,
Thanks a lot for the answer. But I followed your suggestion to use View Injection after reading thoroughly Chapter 7, but always got an exception:
Activation error occured while trying to get instance of type MyView, key ""
Here is the code to lanuch MyView and got that exception:
IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
var newRegionManager = regionManager.CreateRegionManager();
var newShell = new MyNewShell(newRegionManager/*, neweventAggregator*/);
RegionManager.SetRegionManager(newShell, newRegionManager);
RegionManager.SetRegionName(newShell.DemoRegion, RegionNames.ARegionName);
RegionManager.UpdateRegions();
// View injection
IRegion region = newRegionManager.Regions[RegionNames.ARegionName];
MyView newView = ServiceLocator.Current.GetInstance<MyView>(); //this line caused Activation error occured while trying to get instance of type MyView, key ""
// MyView newView = new MyView(); //this line will not cause exception but won't cause the constructor of view model referenced by this view to be executed thus unusable.
region.Add(newView, "NewView");
region.Activate(newView);
newShell.Show();
I have made sure MyView assembly is loaded in bootstrapper, and it has either [Export] or [ViewExport] declaration in the code behind file for MyView class so MEF should be able to find it.
Really appreciate more help from you. Thank you in advance.