How to show a view at application startup

Topics: Prism v4 - Silverlight 4
Nov 18, 2010 at 10:08 AM

I have silverlight prism 4 application called MyApp which has MyApp.ModuleA.xap and MyApp.ModuleB.xap modules. MyApp itself isn't module (no class implementing IModule). So how can I show a view called LoginView (which is defined inside MyApp) after Shell.xaml is initialized (which has region called MainRegion content control)? 

Nov 18, 2010 at 2:07 PM

I think you have some options:

  1. Move LoginView to a module
    1. Module added to MyApp.xap
    2. Module added to ModuleA.xap or ModuleB.xap
    3. Module added to a newly created ModuleC.xap
  2. Register the view with MainRegion while overriding CreateShell within your Bootstrapper
  3. Register the view with MainRegion in Application_Startup after calling Run on your bootstrapper

I personally prefer any option that involves a module because modules give a structured and discoverable place to do that type of activity whereas the other options I mentioned would take some hunting to know that code was even there.

Nov 18, 2010 at 5:19 PM


All options indicated above are possible approaches. Additionally, If you are using MEF, you could use the ViewExportAttribute class to decorate a particular view (LoginView). This attribute is part of the StockTrader Reference Implementation and allows you to indicate in which region the view will be registered. 

Hope this helps.

Fernando Antivero