Activate(view) is not showing?

Topics: Prism v2 - Silverlight 2
May 12, 2009 at 9:31 AM

I've got a Presenter approach to PRISM in place. I've found that for some reason my view's won't register if i do it via the myRegion.Add(MyViewInstance), myRegion.Activate(MyViewInstance).

They do however work if i approach it from regionManager.RegisterViewRegion().

eg:

DspWelcome dspwelcomeview = new DspWelcome();
IRegion welcomeRegion = regionManager.Regions[RegionNames.WelcomeRegion];
welcomeRegion.Add(dspwelcomeview, "view_welcome", false);
welcomeRegion.Activate(dspwelcomeview);

Nothing shows on screen? if i do this however:
regionManager.RegisterViewWithRegion(RegionNames.WelcomeRegion, typeof(DspWelcome));

Disco! :) ...shown. What step am I missing is more my point here? as it feels as whilst a new-up a DspWelcome() its still not being added to the WelcomeRegion's display children?

May 12, 2009 at 8:46 PM

Hi Mossyblog,

 

I don't know your exact scenario and the exact way you are constructing your view and presenter (you might be using the View-First or Presenter-First approaches described in UI Composition), but if you are using Presenter-First you might be having an issue with the order in which your view and presenter are being instantiated.

 

In your code, when you are using View Injection (using the IRegion.Add Method) you are instantiating the view manually (though new DspWelcome();). So if you are using a Presenter-First approach, the presenter is never instantiated and injected into the view. If this is the case, the view is registered but no information is being populated.  

 

When you are using the View Discovery approach (using the RegisterViewWithRegion method) the view gets instantiated through your container (Unity in most cases) so it first instantiates the Presenter to inject it in the view, so everything is in place and works fine.

 

The suggested approach in the documentation to Show a View in a Region Using View Discovery UI Composition with a Presenter-First approach is using the second overload of the RegisterViewWithRegion method:

this.regionManager.RegisterViewWithRegion("MainRegion",

            () => this.container.Resolve<EmployeesPresenter>().View);

 

Hope it helps!

 

Matias Bonaventura

http://blogs.southworks.net/matiasb