Aracılığıyla paylaş


Create a reusable template to style a system control

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 Visual Studio 2012 için Blend or any imported custom control that inherits from the Control class.

To create a copy of the template of a button

  1. Draw a system control on the artboard. For example, select Button JJ170159.05df1779-a68f-436b-b834-a91b7995a3ec(tr-tr,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.

    JJ170159.40c4d9ae-bf61-4492-b0c8-b090a7b9acfb(tr-tr,VS.110).png

    İpucu

    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.

    JJ170159.4818ee6a-ce60-4b79-91c8-3b1871829eea(tr-tr,VS.110).png

  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.

    İpucu

    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.

    JJ170159.475cc7f7-f134-4a39-8ee7-4a5516a2b812(tr-tr,VS.110).png

    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.

    JJ170159.5bb586ea-6adc-4672-b316-0fab8215ff8c(tr-tr,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 JJ170159.c76bbf09-1922-4f45-8d92-9c8ae64ca4a4(tr-tr,VS.110).png 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.

    For more information, see Styling the parts of a Silverlight control template.

Next steps