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 Windows Presentation Foundation custom control library files (.dll). For more information about developing custom control library files see Control Authoring Overview.

Note

Resources, resource dictionaries, and custom control library files are not supported in Microsoft Silverlight 1.0 projects.

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 under Objects and Timeline in the Interaction 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 (WPF only)   To create a resource dictionary that you can share, click the New 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 the Advanced property options Cc295221.d6ba8f4a-b8a2-445a-af0b-a267dfade6e1(en-us,Expression.10).png button next to properties in the Properties panel and selecting Convert to New Resource.

      Note

      You cannot 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 under Objects and Timeline in the Interaction panel, and then in the Object menu, click Edit Control Parts (Template), Edit a Copy. In the Create Style Resource dialog 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 (WPF and Silverlight 2 only)   To create a user control that you can share, you can either create an Expression Blend WPF 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 WPF Control Library project.

    • Create a custom control in Visual Studio (WPF and Silverlight 2 only)   To create a custom control that you can share, create a Class Library or Silverlight 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 WPF Button control, see Try it: Create a custom WPF control.

      Note

      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 User Controls tab of the Asset Library in the Toolbox.

    • Create a custom object in a JavaScript class file   For an example, see the Button class in the ButtonGallery sample that is available from the Samples tab in the Welcome Screen (on the Help menu). For information about how to write JavaScript for your Silverlight 1.0 application, see the Silverlight learning center.

See also

Concepts

XAML editing

Debug Expression Blend applications

Debug Expression Blend applications in Visual Studio 2008

Deploy and publish Expression Blend applications