Timo Korinth

2 Meter, 2 Mark

Extending Blend for Visual Studio (Part 1)

| 1 Comment

Blend for Visual Studio 2012 (previously known as Expression Blend) is a WPF application using MEF (Managed Extensibility Framework) to tie up its modules. In addition to that it brings an own extension API to create and integrate 3rd party modules / extensions. That’s the point where you can jump in and extend Blend with your own code.

The only problem is that there’s practically no documentation or help to get started. So you have to figure it out on your own, or use one of the rare tutorials available online:

To share my knowledge on creating an extension for Blend, I’ve created an own article to help you getting started. This article is divided into two parts. This first part shows you how to setup a Visual Studio solution and how to create a first extension class that is getting loaded by Blend.

Create initial Visual Studio solution

First create a new Visual Studio project. If you want to include user interface code (Controls / Views) a good starting point is the WPF User Control libarary template, as the necessary dll references are already included:

BlendExtensionProjectTemplate

One important note: Blend expects the dll to be in the format: NameOfExtension.Extension.dll. So you have two options:

  1. Name the Visual Studio project accordingly (see Screenshot), or
  2. Setup the assembly name in the preferences of the project (in the application tab).

To complete the project setup, include one or all of the following dlls:

  • Microsoft.Expression.Extensibility.dll
    • Base library, always include this one.
  • Microsoft.Expression.Framework.dll
    • Additional services like IWindowService to add your own Panels to Blend.
  • Microsoft.Expression.DesignSurface.dll
    • All the panels are defined in this assembly.
  • Microsoft.Expression.Utility.dll
    • Additional controls to use in your own Panels.

If you include these assemblies, you can change their Build preferences to CopyLocal = False, as they are all available in the final Blend directory.

To make development life a bit easier, change the following project settings as well, so if you hit F5 in Visual Studio, your assembly will be copied to Blend’s extension folder (\Program Files (x86)\Microsoft Visual Studio 11.0\Blend\Extensions) and Blend will start to debug your code.

BlendExtensionOutputPath

BlendExtensionStartAction

Create package

The first interface you have to use is IPackage from the Microsoft.Expression.Extensibility.dll. Create a new class and implement the IPackage interface. That interface defines two methods:

[Export(typeof(IPackage))]
public class AdvancedResourceTabExtension : IPackage
{
    public void Load(IServices services)
    {
        var windowService = services.GetService();
    }

    public void Unload()
    {
    }
}

The Load method gets called when Blend is starting and loads the extension. The Unload method is called on Exit. To register your extension in Blend (so that Blend can find and load your code), you have to export your class. That’s the MEF Export keyword on your class file. Make sure to use IPackage as the exported type and reference the System.ComponentModel.Composition.dll.

To check if everything works as expected, place a breakpoint in the load method and hit F5. If Blend loads up your code, it calls the load method and passes in a reference to the main service. This service is the main entry point to different other services and is used in a next post (part 2 of this article) to write a more useful extension.

One Comment

  1. I read a lot of interesting content here. Probably you spend a lot of time writing,
    i know how to save you a lot of work, there is an online tool that creates unique, google friendly posts in minutes,
    just type in google – laranitas free content source

Leave a Reply