Share via


Create a reusable template to style a system control (Blend for Visual Studio)

You can customize the appearance of system controls by modifying a copy of the template of the control.

The following procedure uses a button, but you can create a template for any system control that is included with Blend for Visual Studio 2012 or any imported custom control that inherits from the Control class. A Control class represents the base class for UI elements that use a ControlTemplate to define their appearance.

To create a copy of the template of a button

  1. Draw a system control on the artboard. For example, select Button JJ155204.05df1779-a68f-436b-b834-a91b7995a3ec(en-us,VS.110).png from the Tools panel, and then use your mouse to draw it on the artboard.

  2. Use the breadcrumb bar at the top of the artboard to create a copy of the template of the button. Click [Button], click Edit Template, and then click Edit a Copy.

    JJ155204.40c4d9ae-bf61-4492-b0c8-b090a7b9acfb(en-us,VS.110).png

    Tip

    You create a copy because you cannot modify the default template for a system control. Alternatively, you could create an empty template and design your button by importing art assets or drawing new objects.

  3. In the Create Style Resource dialog box, type a name for the template, such as ButtonStyle1.

  4. Under Define in, select where you want the template to be defined:

    • To make the template available to a button object in any document in your application, select Application.

    • To make the template available only to button objects in the current document, select This document.

    • To make the template available only to this button in this document, select Button from the drop-down box beside This document.

  5. Click OK to exit the dialog box and open the template for editing.

    Tip

    The breadcrumb bar makes it easy to switch between editing the template that is applied to an object, and editing the object itself. For example, to exit template-editing mode, click Button in the breadcrumb bar.

    To return to template-editing mode, make sure that the button object is selected (to display the breadcrumb bar for the button), and then click Template in the breadcrumb bar.

    JJ155204.5bb586ea-6adc-4672-b316-0fab8215ff8c(en-us,VS.110).png

Troubleshooting

  • If you do not see the option to Edit Template in the breadcrumb bar, you might have selected a control that does not support templates. For example, layout panels such as Grid  do not use templates. Only controls that inherit from the Control class use templates.

  • You cannot create a template for a user control (a control that inherits from the UserControl class), but you can customize a user control by designing it from scratch.

    .

Next steps