Creating a new MEFContrib project for use with the CompositeWPF and Unity

These were the steps used to create the MEFSDMS application

Recommendation: create a "bin" folder in your solution's root and set your project's build path to it. Under this bin folder create an "extensions" folder; this is where you'll set the MEFUnity build path to (as well as your other parts)
  • Create a new Windows WPF Application
  • Add a reference to the System.ComponentModel.Composition.dll / project (MEF)
  • Add a reference to the MEFContrib.Library and MEFContrib.Library.Interface (MEFContrib)
  • Add a reference to the Microsoft.Practices.Unity.dll / project (Unity)
  • Add a reference to the Microsoft.Practices.Composite.dll / project (CompositeWPF)
  • Add a reference to the Microsoft.Practices.Composite.Wpf.dll / project (CompositeWPF)
  • Add a reference to the Microsoft.Practices.Composite.UnityExtensions.dll / project (CompositeWPF)
  • Add the following source to the App.xaml.cs file: App.xaml.cs source
  • Remove the StartupUri="Window1.xaml" reference from the App.XML; we'll programmatically load the Window1.xaml
<Application x:Class="MEFSDMS.App"
  • Add the following Export attribute to the Window1.xaml.cs file:
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
        public Window1()
  • Add the following ItemsControl element w/Region to your XAML
<Window x:Class="MEFSDMS.Window1"
    Title="MEF SDMS" x:Name="MEFMainShell" >
    <ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" >
  • Run the application - you should get an empty Window. If you get two windows then you failed to remove the StartupUri from the App.xaml file.

Last edited Oct 4, 2008 at 2:31 AM by BillKrat, version 7


No comments yet.