Sharing code

Apart from deploying a complete application, you might want to share pieces of your application, such as XAML elements, XAML resources, user controls, class definition files, or custom control library (.dll) files.

For more information about developing custom control library files see Control Authoring Overview.

To share XAML

  • To share XAML, you can use either of the following methods:

    • Copy and paste complete elements into a text file   To quickly copy a XAML element in Microsoft Expression Blend, you can right-click the element in the Objects and Timeline panel while in Design view, and then select View XAML to switch to XAML view. The entire element will be highlighted so that you can copy it. You can also copy the element by selecting it on the artboard and pressing CTRL+C, and then paste it into another document opened in the same instance of Expression Blend, or a different instance.

    • Create a resource dictionary in Expression Blend   To create a resource dictionary that you can share, click the Create new resource dictionary button in the Resources panel. After you create the resource dictionary, you can then use the Resources panel to move existing resources (such as styles or templates) to the new dictionary, or you can add new resources to the dictionary by clicking Advanced property options Cc295221.12e06962-5d8a-480d-a837-e06b84c545bb(en-us,Expression.30).png next to properties in the Properties panel and selecting Convert to New Resource.


      You can't copy XAML elements and paste them into a resource dictionary, but you can create templates for elements that will be stored in the resource dictionary, and apply those templates to other elements of the same type. To create a template, select an element in the Objects and Timeline panel, and then in the Object menu, click Edit Template, Edit a Copy. In the Create Style Resource dialog box that opens, choose to define the template in the resource dictionary. This creates a copy of the default template for the element and allows you to alter it. You can also create style templates using the Edit Style menu item in the Object menu.

To share controls

  • To share custom controls or user controls, you can use either of the following methods:

    • Create a UserControl in Expression Blend   To create a user control that you can share, you can either create an Expression Blend Control Library project, or add a UserControl to an existing project. After you create your control, you can share the source files (UserControl1.xaml and UserControl1.xaml.cs) or share the .dll that is generated by building the Control Library project.

    • Create a custom control in Visual Studio   To create a custom control that you can share, create a Class Library project in Microsoft Visual Studio 2008. Your class can derive from an existing control. To share your custom control, you can share the source files or share the .dll that is generated by building the Class Library project.

      For an example of a custom control that derives from the Button control, see Try it: Create a custom control with custom properties.


      When you add source code files that contain custom controls to an Expression Blend project, you must build the project before you can see the controls in the Project category of the Assets panel.

See also


Debug Expression Blend applications in Visual Studio 2008


Editing XAML

Debug Expression Blend applications

Deploy and publish Expression Blend applications