Search code examples
navigationprismmef

PRISM navigation without RegionManager, only MEF


We are planning on developing a framework using MEF as the base an pulling in bits of Prism as required.

One of the target assets from prism is the navigation. Can this, however be used with RagionManager ?

We don't want to use RegionManager as it seems like a bit of overkill. Ours is mostly a workflow type application and does not require complex ui composition, which is the primary purpose of regionmanager


Solution

  • Most of the time, navigation is just menu items and I agree, it's a bit overkill.

    What we do with menu items, is register menu items with the Shell so that the Shell can then create the menu, including the look and feel. With MEF this is really simple.

    Start with a MenuItem entity.

    public class MenuItem
    {
         public ICommand ClickCommand { get; private set; }
         public string Path { get; private set; }
         public MenuItem(DelegateCommand command, string path) { //yada yada }
    }
    

    From your modules, you can export instances of those menu items.

    [Export(typeof(MenuItem))]
    public MenuItem MyFirstItem = new MenuItem(
         new DelegateCommand(
             () => MessageBox.Show("woo!")), 
             "My First\Menu Item 1")
         );
    

    And in your shell, you'd just import these and create whatever visual element you are trying to render for menu items. This has the added benefit on not relying on modules to create the right look for navigation elements when you probably want them all to look the same.