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 files (.dll).
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 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.
- Create a resource dictionary in Expression Blend - 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 button next to properties in the Properties panel and selecting
Convert to New Resource.
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 - 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 Visual Studio 2005. Your class can derive from an existing WPF 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 Create a custom control.
For more information about user control and custom control development, see Control Authoring Overview in the Windows Presentation Foundation section on MSDN.
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. |