Export (0) Print
Expand All

Create a control from existing objects

You can use the Make Into Control feature in Microsoft Expression Blend to make a control template out of any objects on the artboard. The Make Into Control tool wraps the objects in a style resource that you can reuse.

Cc295271.alert_tip(en-us,Expression.30).gifTip:

An object in Expression Blend is anything that you place onto the artboard, such as a layout panel, shape, text control, image, button, control template, or any other user interface (UI) design element. Placing a UI element onto the artboard creates an object instance of the element in your application.

  1. If you have not already done so, open or create a new project.

    For more information, see Create a new project.

  2. On the artboard, draw a circle by using Ellipse Cc295271.d7a04618-e35a-44f9-b78c-1f22e38016c1(en-us,Expression.30).png in the Tools panel. To make the ellipse more visible, you can change its appearance by altering its properties under Brushes in the Properties panel.

    For more information, see Apply a brush to an object's fill or stroke.

  3. Right-click the ellipse, point to Group Into, and then click the name of a layout container, such as Grid.

  4. With the grid selected in the Objects and Timeline panel, click Make Into Control on the Tools menu to convert the grid to a button.

    The Make Into Control dialog box opens.

  5. Under Control type, click the type of control you want to create, such as the Button control.

  6. Under Name (Key), select the first radio button (default), and then enter a name to be used to identify the button style. Alternatively, you could select the Apply to all option that would apply the style to all buttons on the artboard that do not already reference a style by name.

  7. Under Define in, click the option that reflects where you want the button style to be defined. Click Application to make the button style available to any document in your application. Click This document (Window: Window) to make the button style available only to the current document. Click Resource dictionary to define the button style in a resource dictionary in your application.

  8. Click OK to exit the Create Style Resource dialog box and to create the button style.

    Notice that in the Objects and Timeline panel, the ellipse object is converted to a button object whose style is set to your new button style.

    Additionally, the button style is listed in the Resources tab in the node where it was defined (for example, in the Window node).

    The new button style as it appears in the Resources tab of Expression Blend
    Cc295271.53d9464b-bf8b-4dcb-90c0-6fb85b0df530(en-us,Expression.30).png

  1. To modify the button style that you just created, right-click the new button object in the Objects and Timeline panel, point to Edit Template, and then click Edit Current.

    The artboard switches to the editing scope of the control template.

    Cc295271.alert_tip(en-us,Expression.30).gifTip:

    There are multiple ways that you can enter the editing scope of a control template. For example, you can view your button style in the Resources tab, and then click the Edit resource button beside the resource name. This takes you to the editing scope of the style, from which you can go to the editing scope of the control template by right-clicking the style object in the Objects and Timeline panel, pointing to Edit Template, and then clicking Edit Current.

    To exit the editing scope of a control template, click Return scope to Cc295271.55844eb3-ed98-4f20-aa66-a6f5b23eeb2b(en-us,Expression.30).png in the Objects and Timeline panel. If you entered the editing scope of the control template from the editing scope of the style, you will be returned to the style. Click the Return scope to button again to return to the editing mode of the document.

    Cc295271.alert_tip(en-us,Expression.30).gifTip:

    The Make Into Control tool wraps the original object (the ellipse) in a style resource that contains a control template. The style defines the properties that are set on the object to which the style is applied (in this case, a button object). The control template defines the states, structure, and appearance of the object.

  2. Inside the control template is a Grid panel that contains the original object (the ellipse) and a ContentPresenter element that displays the content of the button object. Placing your object inside a Grid panel enables you to quickly add and arrange other elements.

    The structure of the control template for the new button style
    Cc295271.d16a098c-d0c2-4f72-8e2f-19ce6469c4f8(en-us,Expression.30).png

    You can see how the style and the control template are related by looking at the Extensible Application Markup Language (XAML) for the resource. For example, the structure of the button style might look like the following:

      <Window.Resources>
        <Style x:Key="ButtonStyle1" ...>  
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type Button}">  
                <Grid>
                  <Ellipse>
                    ...
                  </Ellipse>
                  <ContentPresenter .../>
                </Grid>
                <ControlTemplate.Triggers>
                  ...
                </ControlTemplate.Triggers>
              </ControlTemplate>  
            </Setter.Value>
          </Setter>
        </Style>  
      </Window.Resources>
    
  3. In the Triggers panel, define the states of the button as desired. For example, click IsMouseOver = True to activate trigger recording for the state when the user passes their mouse over the button. Select the ellipse in the Objects and Timeline panel, and then under Appearance in the Properties panel, change the Fill property of the ellipse to a different color. Notice that a new property change for ellipse.Fill is added in the Triggers panel under Properties when active, as shown in the following image.

    Cc295271.alert_note(en-us,Expression.30).gifNote:

    You might have to adjust the size of the Triggers panel to see the Properties when active section. To adjust the size, click and drag the borders of the panel and the border within the panel.

    The Triggers panel after changing the Fill of the ellipse when the pointer is over the button
    Cc295271.6be5825d-f291-410b-bc75-423fee8f5d00(en-us,Expression.30).png
  4. You can also add animation to the button. For example, in the Triggers panel, click IsPressed = True to activate trigger recording for the state when the user clicks the button. With the ellipse still selected in the Objects and Timeline panel, hold the SHIFT and ALT keys while you drag one corner of the ellipse. (The SHIFT+ALT keyboard shortcut maintains the center point of the object.)

    Alternatively, you can add more complicated animation by creating a new storyboard and triggering that storyboard from an Event Trigger for the IsPressed event.

    For more information, see Writing code that will respond to events.

  5. After you have defined the states of the button as desired, click Return scope to Cc295271.55844eb3-ed98-4f20-aa66-a6f5b23eeb2b(en-us,Expression.30).png in the Objects and Timeline panel to return to the editing scope of the document.

  6. To test the states, click Run Project on the Project menu (or press F5), and then see if the button states are working properly. For example, when you move the pointer over the button, the fill color should change.

  1. Make sure that you are in the editing scope that you want. You can apply a style to a button in any scope, including within the scope of a control template.

  2. On the artboard, draw a button by using Button Cc295271.05df1779-a68f-436b-b834-a91b7995a3ec(en-us,Expression.30).png in the Tools panel.

  3. Right-click the new button object in the Objects and Timeline panel, point to Edit Template, point to Apply Resource, and then select your button style from the list.

    You can also use the Edit Style and Edit Template commands on the Object menu to apply a style resource.

    Applying the button style to a button object, by using the right-click method
    Cc295271.dc12debc-7711-47d9-84ce-10322a384397(en-us,Expression.30).png

Community Additions

ADD
Show:
© 2014 Microsoft