2011-09-29 20 views
6

Actualmente estoy trabajando en una aplicación que usa PRISM 4 para dividir sus funcionalidades en diferentes módulos.¿Es posible mostrar un shell solo una vez que se hayan cargado todos los módulos?

me di cuenta de que mi solicitud de Shell, que tiene puntos de vista de los módulos en sus regiones, se carga y se muestra antes de cargar los módulos.

Esto significa que la Shell se muestra primero, y una cantidad considerable de tiempo más tarde (alrededor de la mitad de un segundo), los módulos son cargados y las vistas insertan en las regiones de la concha. Es bastante molesto, ya que el usuario recibe un shell vacío en el arranque, que no es muy profesional.

¿Hay alguna manera de detectar cuándo se han cargado todos los módulos? ¿Algún método que pueda anular en el programa de arranque?

Si pudiera, me gustaría ocultar la Shell (o mostrar un embellecedor de carga) hasta que todos los módulos se han cargado.

+2

No creo que el w Hago lo que necesita, pero ¿ha mirado una SplashScreen? – Paparazzi

+0

No estaba al tanto del SplashScreen, lo investigaré, gracias. Sin embargo, no estoy seguro si esto resolverá el problema, ya que aún tendré que determinar cuándo terminaron de cargarse los módulos. –

Respuesta

3

Encontré una solución relativamente simple.

Mi aplicación tiene una clase llamada ShellHandler, que es instanciado en el programa previo e inscrita en el Contenedor La unidad como un conjunto unitario:

Container.RegisterType<IShellHandler, ShellHandler>(new ContainerControlledLifetimeManager()); 

creé en mi ShellHandler un método que puede ser utilizado por los módulos a la bandera a sí mismos como cargado:

/// <summary> 
/// Method used to increment the number of modules loaded. 
/// Once the number of modules loaded equals the number of modules registered in the catalog, 
/// the shell displays the Login shell. 
/// This prevents the scenario where the Shell is displayed at start-up with empty regions, 
/// and then the regions are populated as the modules are loaded. 
/// </summary> 
public void FlagModuleAsLoaded() 
{ 
    NumberOfLoadedModules++; 

    if (NumberOfLoadedModules != ModuleCatalog.Modules.Count()) 
     return; 

    // Display the Login shell. 
    DisplayShell(typeof(LoginShell), true); 
} 

por último, en mi clase ModuleBase, que todos los módulos implementan, he creado un método abstracto que se llama durante el proceso de inicialización:

/// <summary> 
/// Method automatically called and used to register the module's views, types, 
/// as well as initialize the module itself. 
/// </summary> 
public void Initialize() 
{ 
    // Views and types must be registered first. 
    RegisterViewsAndTypes(); 

    // Now initialize the module. 
    InitializeModule(); 

    // Flag the module as loaded. 
    FlagModuleAsLoaded(); 
} 

public abstract void FlagModuleAsLoaded(); 

Cada módulo resuelve ahora la instancia del singleton ShellHandler a través de su constructor:

public LoginModule(IUnityContainer container, IRegionManager regionManager, IShellHandler shellHandler) 
     : base(container, regionManager) 
{ 
     this.ShellHandler = shellHandler; 
} 

Y finalmente implementar el método abstracto de ModuleBase:

/// <summary> 
/// Method used to alert the Shell Handler that a new module has been loaded. 
/// Used by the Shell Handler to determine when all modules have been loaded 
/// and the Login shell can be displayed. 
/// </summary> 
public override void FlagModuleAsLoaded() 
{ 
    ShellHandler.FlagModuleAsLoaded(); 
} 
7

usted puede mostrar su punto de vista de Shell después de que se inicialicen los módulos:

protected override void InitializeShell() 
{ 
    Application.Current.MainWindow = (Window)Container.Resolve<ShellView>(); 
} 

protected override void InitializeModules() 
{ 
    base.InitializeModules(); 
    Application.Current.MainWindow.Show(); 
} 
Cuestiones relacionadas