Styling the parts of a Silverlight control template

Ee341465.0b2c798e-86c6-4ea2-a8a6-5cf1f12be1e2(en-us,Expression.30).png

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. Other objects are optional, such as the small increase and decrease RepeatButton objects that move the Thumb in a ScrollBar 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
Ee341465.5fdb8c23-16c9-48df-a89b-12652543402e(en-us,Expression.30).png

Working with parts

Microsoft Expression Blend 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 Ee341465.6cf58c39-edba-4a0e-acbc-1da272f9a387(en-us,Expression.30).png 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 Ee341465.6cf58c39-edba-4a0e-acbc-1da272f9a387(en-us,Expression.30).png 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 Ee341465.64d085f2-3d49-4b74-8070-4d7dae18dc28(en-us,Expression.30).png 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, an icon Ee341465.718cdd76-8d28-4e62-b016-0d1b09be233a(en-us,Expression.30).png appears next to the part in the Parts panel, and a warning icon Ee341465.01c42440-bc71-4448-bc6a-1f6c790e6021(en-us,Expression.30).png appears 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