Condividi tramite


Styling the parts of a Silverlight control template

JJ170618.0b2c798e-86c6-4ea2-a8a6-5cf1f12be1e2(it-it,VS.110).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. 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

JJ170618.5fdb8c23-16c9-48df-a89b-12652543402e(it-it,VS.110).png

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 JJ170618.6cf58c39-edba-4a0e-acbc-1da272f9a387(it-it,VS.110).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 JJ170618.6cf58c39-edba-4a0e-acbc-1da272f9a387(it-it,VS.110).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 JJ170618.64d085f2-3d49-4b74-8070-4d7dae18dc28(it-it,VS.110).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, a warning icon JJ170618.718cdd76-8d28-4e62-b016-0d1b09be233a(it-it,VS.110).png 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.

Vedere anche

Concetti

Styling tips for common Silverlight controls