Share via


Create a reusable template to style a system control (Windows Phone)

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  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.

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.

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

  2. 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.

  3. 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.

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.

You can customize the appearance of the system control by modifying properties in the template you just created. For more information, see Modify the appearance of a system control in different states (Windows Phone).

You can change the time it takes the button to expand when the pointer moves over it. For more information, see Modify the transition time between state changes (Windows Phone).

You can apply this template to another button in your project, or draw a new button that already has the template assigned.