2

メニュー項目をクリックするとEventAggregatorを使用してイベントを公開するMenuコントロールを使用して、アプリケーションを介したナビゲーションを実装しました。以下のようなもの、

this.eventAggregator.GetEvent<ViewRequestedEvent>()
                    .Publish(new BusinessObject.Model.MenuModel
                    {
                        Module = "Dashboard",
                        PresenterClass = "DashboardViewModel"
                    });

私のアプリケーションのほとんどのモジュールは、このイベントのサブスクライバーです。フィルタを使用して、モジュールに関連するイベントのみをサブスクライブします

this.eventAggregator.GetEvent<ViewRequestedEvent>()
            .Subscribe(LoadViewRequest, ThreadOption.UIThread, true, i => i.Module == "Dashboard");

ビューのリクエストは次のように処理されます。

private void LoadRequestedView(MenuModel menuItem)
{
    try
    {
        IDashboardViewModel viewModel = this.container.Resolve(Type.GetType(menuItem.PresenterClass)) as IDashboardViewModel;
        this.regionManager.Regions["ViewRegion"].Add(viewModel.View);
        this.regionManager.Regions["ViewRegion"].Activate(viewModel.View);
        this.eventAggregator.GetEvent<ViewNotificationEvent>().Publish(menuItem.Description);
    }
    catch (ResolutionFailedException) { }
}

この実装をどのように評価しますか?あなたがそれが悪いと思うなら、私がそれを改善するのを手伝うか、より良い代替案を提案してください。

4

1 に答える 1

0

このモデルでは、関心の分離がある程度不足していると思います。私は通常、シェルへのプレゼンテーションを維持しようとします。私がこれをどのように実装したかについては、この質問を参照してください。それは物事を単純化し、RegionManagerのアイデアをモジュールから抽象化します。

モジュールとPrismのアプリケーションの統合別名CompositeWpf

于 2009-11-05T13:43:56.103 に答える