Bagikan melalui


Styling the parts of a Silverlight control template

0b2c798e-86c6-4ea2-a8a6-5cf1f12be1e2

To make a Microsoft Silverlight control look the way that you want it to, you can style it by modifying the template of the control. The behavior of the control is defined in code that you don't see. When the code needs to manipulate objects in the template, the code refers to those objects by name and type. Some objects in the template are mandatory, such as the Popup object that displays the list of items in a ComboBox control. The objects in the template that are referenced by the code are called parts. You can view the parts in the Parts panel when you are editing a control template in a Silverlight application.

The parts of a ComboBox control template

5fdb8c23-16c9-48df-a89b-12652543402e

Working with parts

Blend for Visual Studio 2012 makes it easy to design control templates by providing a list of parts in the Parts panel when you are editing a template. If a part is assigned to an object in the template, an icon 6cf58c39-edba-4a0e-acbc-1da272f9a387 appears next to the part name in the Parts panel. You can double-click the part name to automatically select the object to which it is assigned. In the Objects and Timeline panel, the same icon 6cf58c39-edba-4a0e-acbc-1da272f9a387 appears next to the object that is assigned to the part.

Other objects can exist in the template to dress up the appearance of the control, but each part plays a role in the appearance and behavior of the control to which the template is applied.

If a part is not assigned to an object in the template, an icon 64d085f2-3d49-4b74-8070-4d7dae18dc28 appears next to the part in the Parts panel. You can assign that part to an object in the template, which will convert the object into the correct type if the object isn't already of the correct type. Alternatively, you can double-click the part in the Parts panel to create the correctly named and typed object in the template.

If a part is assigned to an object of the wrong type, a warning icon 718cdd76-8d28-4e62-b016-0d1b09be233a appears next to the part in the Parts panel and also next to the object in the Objects and Timeline panel. You can clear the part assignment and then convert the object to the correct type of the part, assign the part to a different object, or create a new object by double-clicking the part name in the Parts panel.

For more information, see Assign template parts to objects.

For detailed information about converting objects into controls and working with the parts of common templates, see Styling tips for common Silverlight controls.

See Also

Concepts

Styling tips for common Silverlight controls