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 Blend for Visual Studio 2012, you can right-click the element in the Objects and Timeline panel while in Design view, and then select View Source to view the source code of the element. 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 Blend, or a different instance.

    • Create a resource dictionary in 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 options 12e06962-5d8a-480d-a837-e06b84c545bb next to properties in the Properties panel and selecting Convert to New Resource.

      Note

      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 object 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 object 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 Blend   To create a user control that you can share, you can either create an 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 2012. 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 Creating custom controls.

      Note

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

See Also

Tasks

Debug Blend applications in Visual Studio

Concepts

Editing XAML

Debug applications

Deploy and publish applications