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"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>
  • Add the following Export attribute to the Window1.xaml.cs file:
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    [Export("MainWindow")]
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
    }
  • Add the following ItemsControl element w/Region to your XAML
<Window x:Class="MEFSDMS.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cal="http://www.codeplex.com/CompositeWPF"
    Title="MEF SDMS" x:Name="MEFMainShell" >
    
    <ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion" >
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <DockPanel/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</Window>
  • 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

Comments

No comments yet.