How to: Enable a Solution to Use WPF Extensions

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
To create client business applications using current Microsoft technologies, see patterns & practices' Prism.

The Smart Client Software Factory includes Composite UI Application Block extensions for Windows Presentation Foundation (WPF) that allow you to use WPF controls as CAB SmartParts. This topic describes how you can enable an existing smart client application to use the extensions for WPF.

For more details about the WPF extensions, see Composite UI Application Block Extensions for WPF.

This topic assumes that you have an existing smart client application that is not enabled to use the Composite UI Application Block extensions for WPF.

If you are creating a solution from scratch, you can use the Smart Client Application template which unfolds a solution already enabled to use the extensions. For more information, see How to: Create Smart Client Solutions.

The following steps describe how to enable an existing solution to use the extensions for Windows Presentation Foundation.

To enable the extensions for WPF in an existing smart client solution

  1. Open the smart client solution in Visual Studio 2010.
  2. Add a reference to the Microsoft.Practices.CompositeUI.WPF.dll assembly (which contains the code for the extensions) in the following projects:
    • Shell
    • Infrastructure.Library
    • Infrastructure.Layout (only if you created the solution with a separate project for the Shell layout)

    To do this, right-click the projects, select Add Reference and browse for the assembly in the Lib folder of your solution.

  3. Open the file SmartClientApplication.cs in the Infrastructure.Library project, and update the signature of the SmartClientApplication class to inherit from the Microsoft.Practices.CompositeUI.WPF.WPFFormShellApplication base class, as shown in the following example.
    public abstract class SmartClientApplication<TWorkItem, TShell> : Microsoft.Practices.CompositeUI.WPF.WPFFormShellApplication<TWorkItem, TShell>
    
    Ff699234.note(en-us,PandP.10).gifNote:
    Note: The WPFFormShellApplication adds a custom ObjectBuilder strategy and a service to the root WorkItem. These components are required to use WPF controls as CAB SmartParts.

  4. Replace all the workspaces in your application with the WPF workspaces included in the extensions for WPF. The easiest way to do this is to open the designer files (files ending with Designer.cs) for the ShellForm and views that contain workspaces and update the namespaces for the workspaces to be Microsoft.Practices.CompositeUI.WPF instead of Microsoft.Practices.CompositeUI.WinForms. For example, if you have the following workspace declaration shown in the following code.
    private Microsoft.Practices.CompositeUI.WinForms.DeckWorkspace _rightWorkspace;
    

    Replace it with the following code.

    private Microsoft.Practices.CompositeUI.WPF.DeckWorkspace _rightWorkspace;
    

    Otherwise, you can use the designer view to manually remove the Windows Forms workspaces and add the WPF workspaces.

Any project that contains a WPF control must have the following Import statement.

Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />

When you use the Add WPF-View recipe to add a WPF view to a project, the recipe modifies the project file to add this declaration (if the declaration does not already exist in the file). This means that if you do not use the WPF-View recipe, you must manually modify the project file to add the Imports statement.

Your solution will be enabled to use the Composite UI Application Block extensions for WPF.

The following are tasks that you typically perform after enabling a solution to use the extensions for WPF:

  • Add WPF views with presenters. For information about how to do this, see How to: Add a WPF-View with a Presenter.
  • Update existing WPF controls to follow the Model-View-Presenter pattern. To help you do this, you can use the Add WPF-View with presenter recipe. For more information, see How to: Add a WPF-View with a Presenter.
  • Add the WPF workspaces to the Toolbox. To do this, follow these steps:
    1. Right-click the Toolbox, and then click Choose Items.
    2. On the .NET Framework Components tab, browse to the Microsoft.Practices.CompositeUI.WPF.dll assembly, and then click Open.
    3. Make sure the WPF workspaces are selected, and then click OK.
Show: