簡體   English   中英

如何使用MEF和MVVM將PRISM模塊添加到工具欄

[英]How to add PRISM modules to Toolbar using MEF and MVVM

我將PRISM 4.0和MEF用作容器。 我在Shell中定義了2個區域,即ToolBar和MainRegion。 使用自定義的RegionBehaviour-AutoPopulateExportedViewsBehaviour,使用我的ToolBarModule自動填充工具欄區域。 我的MainRegion可以包含1個或多個View模塊,這些模塊將通過第三方停靠布局管理器停靠。

我在創建工具欄按鈕以代表應用程序中的可用視圖時遇到麻煩。 我的想法是使用ToolBarService或Event模式,以便每個View模塊都可以以分離的方式向ToolBar注冊自己。

但是,直到我調用RegionManager.RegisterViewWithRegion ...,似乎沒有調用我的View Module構造函數。

如何控制模塊的初始化,以便它們可以在ToolBar中注冊。 因此,允許他們添加按鈕,但實際上不顯示視圖本身。 僅當單擊剛剛注冊的視圖的按鈕時,才會顯示該視圖。

謝謝

我如何控制模塊的初始化,以便它們可以在ToolBar中注冊但不能初始顯示?

我不確定你的意思。

我了解您希望模塊在加載時注冊其自己的導航部分。 我有類似的情況,我在頂部有菜單欄,在下面有按鈕欄。 每個模塊在加載時-使用初始化代碼插入自己的按鈕/菜單:

public void Initialize()
        {
            this.RegionManager.RegisterViewWithRegion(RegionNames.Menu, typeof(NavigationView));
            this.RegionManager.RegisterViewWithRegion(RegionNames.Toolbar, typeof(ToolbarNavigationView));
        }

這些區域具有實際的按鈕/項目,當按下按鈕/項目時,它們會調用其他內容。 例如,這是NavigationViewModel

namespace IDATT.Module.SystemManager.ViewModels
{
    using System;
    using System.ComponentModel.Composition;

    using Microsoft.Practices.Prism.Regions;

    [Export]
    public class NavigationViewModel
    {
        [Import]
        public ISecurityService SecurityService { get; set; }

        [Import]
        public IRegionManager RegionManager { get; set; }

        public void Mail()
        {
            this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MailView).Name, UriKind.Relative));
        }

        public void MaintainUser()
        {
            this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MaintainUserView).Name, UriKind.Relative));
        }

        public void MaintainGroup()
        {
            this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MaintainGroupView).Name, UriKind.Relative));
        }

        public void MaintainMailTemplate()
        {
            this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(MaintainMailTemplateView).Name, UriKind.Relative));
        }

        public void SetUpOptions()
        {
            this.RegionManager.RequestNavigate(RegionNames.Tabs, new Uri(typeof(SetUpSystemManagerOptionsView).Name, UriKind.Relative));
        }

        public void Logout()
        {
            this.SecurityService.Logout();
        }
    }
}

看起來我可以通過使用自定義RegionBehaviour來“強制”視圖模塊的構造函數。 在其中,我可以將視圖模塊轉換為特定的基本視圖或接口類型,然后調用a函數。 然后,這會將我的視圖注冊到工具欄,但不一定在應用程序的“主要”區域中顯示該視圖。

謝謝你的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM