Hi,
You are right, the view injection and view discovery approaches add views at very different times. Hence it seems that the problem you are experiencing is mainly caused by a timing issue between the AutoPopulateRegionBehavior (in charge of the view discovery mechanism), the RegionManagerRegistrationBehavior (in charge of adding a region in the corresponding region manager) and the RegionManagerAwareBehavior.
Based on my understanding, the regions behaviors are attached to and executed in the regions in the order they were registered. By default in Prism, the AutoPopulateRegionBehavior is registered first, and hence, under some circumstances, it can add a view to a region before other behaviors are attached to it. For example, it can add a view before the RegionManagerAwareBehavior get to be attached to the region, and as a result the view's RegionManager property would not be set by it.
As a quick test, I tried changing the order in which the region behaviors are registered and as a result the RegionManager property could be set in a ClientView added through view discovery. To do this, you need to override the ConfigureDefaultRegionBehaviors method of the Bootstrapper, to do something like this:
I also moved the registration of the RegionManagerRegistrationBehavior as we need it to execute first in order for the RegionManagerAwareBehavior to work correctly.
I hope this helps,
Damian Cherubini
http://blogs.southworks.net/dcherubini
You are right, the view injection and view discovery approaches add views at very different times. Hence it seems that the problem you are experiencing is mainly caused by a timing issue between the AutoPopulateRegionBehavior (in charge of the view discovery mechanism), the RegionManagerRegistrationBehavior (in charge of adding a region in the corresponding region manager) and the RegionManagerAwareBehavior.
Based on my understanding, the regions behaviors are attached to and executed in the regions in the order they were registered. By default in Prism, the AutoPopulateRegionBehavior is registered first, and hence, under some circumstances, it can add a view to a region before other behaviors are attached to it. For example, it can add a view before the RegionManagerAwareBehavior get to be attached to the region, and as a result the view's RegionManager property would not be set by it.
As a quick test, I tried changing the order in which the region behaviors are registered and as a result the RegionManager property could be set in a ClientView added through view discovery. To do this, you need to override the ConfigureDefaultRegionBehaviors method of the Bootstrapper, to do something like this:
protectedoverride IRegionBehaviorFactory ConfigureDefaultRegionBehaviors() { // We add the RegionManagerRegistrationBehavior and RegionManagerAwareBehavior before the other behaviors IRegionBehaviorFactory behaviors = this.Container.Resolve<IRegionBehaviorFactory>(); behaviors.AddIfMissing(RegionManagerRegistrationBehavior.BehaviorKey, typeof(RegionManagerRegistrationBehavior)); behaviors.AddIfMissing(RegionManagerAwareBehavior.BehaviorKey, typeof(RegionManagerAwareBehavior)); // The we invoke the base method to register the rest of the behaviorsreturnbase.ConfigureDefaultRegionBehaviors(); }
I hope this helps,
Damian Cherubini
http://blogs.southworks.net/dcherubini