Click here to Skip to main content
15,884,099 members
Articles / Desktop Programming / WPF

Prism 4 MEF Application

Rate me:
Please Sign up or sign in to vote.
4.70/5 (18 votes)
13 Sep 2011CPOL8 min read 119.3K   8.6K   86  
Building a Prism 4 application using MEF
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Regions;
using Prism4MefDemo.Infrastructure.Data;
using Prism4MefDemo.Infrastructure.Models;

namespace Prism4MefDemo.ModuleOne.Controllers
{
    [Export(typeof(IModuleController))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class ModuleController : IModuleController
    {

        [Import]
        public IRegionManager regionManager;

        [ImportingConstructor]
        public ModuleController()
        {
            ViewObjects = new ViewObjects
                              {
                                  new ViewObject
                                      {
                                          Section = "Module One",
                                          Title = "View 1",
                                          View = "/View1"
                                      },
                                  new ViewObject
                                      {
                                          Section = "Module One",
                                          Title = "View 2",
                                          View = "/View2"
                                      }
                              };
            ShowViewCommand = new DelegateCommand<ViewObject>(OnShowExecuted);
        }

        public DelegateCommand<ViewObject> ShowViewCommand { get; private set; }

        public ViewObjects ViewObjects { get; private set; }

        /// <summary>
        /// Showing the selected view in the Workspace Region
        /// </summary>
        /// <param name="viewObject">View object that has been selected in the binding</param>
        private void OnShowExecuted(ViewObject viewObject)
        {

            Uri viewNav = new Uri(viewObject.View, UriKind.Relative);
            regionManager.RequestNavigate(RegionNames.WorkspaceRegion, viewNav);

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions