Looking for Prism example of Modules loading themselves into a menu

前端 未结 2 1973
忘掉有多难
忘掉有多难 2020-12-08 05:22

Does anyone know of WPF code examples using Prism in which modules each register themselves as a menuitem in a menu within another module?

(I\'ve cu

2条回答
  •  北海茫月
    2020-12-08 06:24

    Update:

    I created a sample for you. It's here: Sample

    It's got a few things you've probably not thought of yet, like a contract that will allow your modules to control your shell (so you can do stuff like Open Window, that kind of thing). It's designed with MVVM in mind... I dunno if you are using that, but I would consider it.

    I tried for a few minutes to get the tab titles correct, but I ended up leaving off with "A Tab". It's left as an exercise for you if you go with a tabbed UI. I've designed it to be lookless, so you can replace the XAML in the Shell.xaml without breaking anything. That's one of the advantages to the RegionManager stuff if you use it right.

    Anyway, good luck!


    I've never seen an example of this, but you'd have to implement this yourself.

    You'd have to create your own interface, something like this:

    public interface IMenuRegistry
    {
         void RegisterViewWithMenu(string MenuItemTitle, System.Type viewType);
    }
    

    Your Modules then would declare a dependency on an IMenuRegistry and register their views.

    Your implementation of IMenuRegistry (which you would likely implement and register in the same project that hosts your Bootstrapper) you would add those menu items to your menu or treeview or whatever you are using for your menu.

    When a user clicks on an item you'll have to use your Bootstrapper.Container.Resolve(viewType) method to create an instance of the view and stuff it in whatever placeholder you want to show it in.

提交回复
热议问题