Dec 3, 2014 at 11:18 PM
Edited Dec 3, 2014 at 11:20 PM
I was referring to the thread
View not connecting to ViewModel using MEF
. I have similar scenario but a few addons. The application is composed of several modules and the Shell has defined main regions. Each module has a view(userControl) and viewmodel and the views are loaded in the
shell regions on demand
. The problem is the Views are composed of child usercontrols each having their own ViewModel. So I chose to inject the child controls in a scope region defined in the view as I could have mulitple instances of the View.
But somehow I am not getting through using MEF. The following is pseudo code and app structure.
- Shell has Mainregion defined. Parent View(s) load in this MainRegion on demand.
- Parent View which FooParent has a xaml where in I define a region.
<ContentControl prism:RegionManager.RegionName ="FooChildRegion" />
- The FooChildUsercontrol code behind class is marked with [Export] attribute.
- FooParentModule has a initialize method with a regionmanager importing constructor
- Code in Initialize method of Module
IRegion foochildregion = this._regionManager.Regions["FooChildRegion"]; //This blows.
FooChildView fooChildView = new FooChildView();
IRegionManager allocationViewRegionManager = foochildregion .Add(fooChildView , null, true);
foochildregion .Activate(fooChildView );
The first line for getting the instance for FooChildRegion blows as the module is initialized on startup and the view is loaded on demand.
Any idea what I am missing here?