Partager via


Assign template parts to objects

JJ171020.0b2c798e-86c6-4ea2-a8a6-5cf1f12be1e2(fr-fr,VS.110).png

Blend for Visual Studio 2012 makes it easy to design control templates by providing the list of parts for the template in the Parts panel. You can assign those parts to objects in your template in several ways.

For detailed examples of converting objects into the parts of control templates, see the topics under Styling tips for common Silverlight controls.

ConseilConseil

If an object in the Objects and Timeline panel is assigned to a part, but the object is a child of a collapsed parent object, the Is a control part icon JJ171020.6cf58c39-edba-4a0e-acbc-1da272f9a387(fr-fr,VS.110).png will appear next to the parent object to let you know that the part is contained underneath.

To assign a part to an existing object

  1. In the Objects and Timeline panel, right-click the object that you want to assign to a part, point to Make Into Part of [control name], and then select the part name from the list that appears.

    Converting a Grid of objects into the HorizontalThumb part of a Slider control

    JJ171020.8a982f33-c0ec-4bf5-b892-37f09ede286a(fr-fr,VS.110).png

    ConseilConseil

    If the Make Into Part of [control name] command is not enabled, you might have more than one object selected. If you want to convert multiple objects into a control, you first have to group them into a layout panel such as a Grid layout panel.

    For more information, see Group or ungroup objects.

  2. If the object that you selected does not match the type of the part, the Make Into Part of [control name] command will attempt to convert the object. If the type of the part is a control that supports templates (such as a Thumb control), your object will be converted into a template for that control. A Make Into Part dialog box will appear. Type a name for your template, select a location where the template will be stored, and then click OK.

    For information about locations, see Create a resource.

    Creating a template for a Thumb control that will be applied to the HorizontalThumb object

    JJ171020.72f2820d-03ea-43e8-a26d-d0bc0ea97c83(fr-fr,VS.110).png

    After you click OK, you will be in template-editing mode for the new object. To go back to template-editing mode for the template you started working on, click Return scope to JJ171020.55844eb3-ed98-4f20-aa66-a6f5b23eeb2b(fr-fr,VS.110).png in the Objects and Timeline panel, or click the third button in the breadcrumb bar at the top of the artboard.

    Returning to the template that you started with

    JJ171020.6427bc3d-1cf4-44bf-934c-65b82c4c5ee0(fr-fr,VS.110).png

  3. An icon JJ171020.6cf58c39-edba-4a0e-acbc-1da272f9a387(fr-fr,VS.110).png, indicating that the part has been assigned, appears next to the object in the Objects and Timeline panel, and next to the part in the Parts panel.

To assign a part by creating a new object

  1. In the Parts panel, double-click the name of the part that you want to create in your template.

    An object is created in your template and assigned to the part. An icon JJ171020.6cf58c39-edba-4a0e-acbc-1da272f9a387(fr-fr,VS.110).png indicating that the part has been assigned appears next to the object in the Objects and Timeline panel, and next to the part in the Parts panel.

  2. You can now modify the newly-created object.

    ConseilConseil

    When you create an object by double-clicking a part in the Parts panel, only the root object is created, so that you can fully customize the object. For example, when you double-click the ScrollViewer part while modifying the template of a ListBox control, a ScrollViewer object is created in the template, but it does not contain a child ItemsPresenter object, as the default ListBox template does. This allows you to choose the items control that you want to use. Content will not appear in your customized ListBox object until you add an ItemsPresenter or other items control as the child object of the ScrollViewer object in the template.

    For more information about individual control templates, see the topics under Styling tips for common Silverlight controls.

Broken part assignment

If you converted objects into a control using the Make Into Control command, and an object had the same name as one of the control parts but not the correct type, the part assignment will not work. You can clear the incorrect part assignment and then convert the object into the part.

To fix a broken part assignment

  1. In the Objects and Timeline panel, right-click the object that is incorrectly assigned to a part, and then click Clear Part Assignment.

    The icon JJ171020.01c42440-bc71-4448-bc6a-1f6c790e6021(fr-fr,VS.110).png that indicated that the part was incorrectly assigned is removed from next to the object in the Objects and Timeline panel. In the Parts panel, an icon JJ171020.64d085f2-3d49-4b74-8070-4d7dae18dc28(fr-fr,VS.110).png indicating that the part is now unassigned appears next to the part.

  2. If the part was incorrectly assigned because the object is not the correct type, you might be able to convert the object into the correct type. Right-click the object, click Make Into Part of [control name], and then click the name of the part from the list that appears.

Voir aussi

Concepts

Styling tips for common Silverlight controls