2011-09-29 9 views
6

私は現在、PRISM 4を使用してさまざまなモジュールで機能を分けているアプリケーションに取り組んでいます。すべてのモジュールがロードされて初めてシェルを表示できますか?

モジュールの読み込み前に、モジュールのビューをその領域に保持しているアプリケーションのShellが読み込まれて表示されていることに気付きました。

これは、シェルが最初に表示され、かなりの時間(約0.5秒)後に、モジュールが読み込まれ、ビューがシェルの領域に挿入されることを意味します。起動時にユーザーが空のシェルで挨拶されるので、それはむしろ面倒です。これはあまりプロフェッショナルではありません。

すべてのモジュールがロードされたときに検出する方法はありますか?ブートストラップでどのような方法でも上書きできますか?

可能であれば、すべてのモジュールがロードされるまでシェルを非表示にしたい(または読み込み側のアドオンを表示する)ようにします。

+2

私はwとは思わない病気はあなたが必要とするものですが、あなたはSplashScreenを見ましたか? – Paparazzi

+0

私はSplashScreenを認識していませんでした。モジュールがいつロードを完了したかを判断する必要があるので、これで問題が解決するかどうかはわかりません。 –

答えて

3

私は比較的簡単な解決策を見つけました。私は私のShellHandlerにフラグへのモジュールで使用可能なメソッドを作成し

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

私のアプリケーションはシングルトンとしてユニティコンテナにブートストラップでインスタンス化し、登録されているShellHandlerという名前のクラスを、持っていますロードされたとして自分自身:

/// <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); 
} 

は最後に、すべてのモジュールが実装私ModuleBaseクラス、で、私は、初期化プロセス中に呼び出される抽象メソッドを作成しました0

/// <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(); 

各モジュールは、今自分のコンストラクタでShellHandlerシングルトンのインスタンスを解決します

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

そして最後に、彼らは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

あなたのシェルのビューを表示することができますモジュールが初期化された後:

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

protected override void InitializeModules() 
{ 
    base.InitializeModules(); 
    Application.Current.MainWindow.Show(); 
} 
関連する問題