Content Index Search
 

Create a rollover button

A rollover effect can be created in a button template by changing the appearance of your button depending on user interaction. As an alternative to triggering an animation timeline or triggering property changes to produce a rollover effect, you can use the following procedure to create multiple Grid panels to represent each state of the button, and then toggle the Visibility properties of each Grid panel.

To create a rollover effect on a button

  1. Draw a SimpleButton on the artboard in Expression Blend.
    Tip The simple style controls are available from the Simple Styles category of the Controls tab in the Asset Library Asset Library button. After you select a simple style control from the list, you can draw it on the artboard.
  2. Right-click the button under Objects and Timeline, point to Edit Control Parts (Template), and then click Edit Template. If you do not want to change the SimpleStyles.xaml resource dictionary, you can click Edit a Copy instead of Edit Template, to create a new template and save it in the document. For more information about creating a copy, see Create a resource.
    Tip To exit the template-editing mode and return to the scope of your document: click the Scope up button Scope up button, which is above the element tree in the Interaction panel.

    To return to template editing mode for an existing template: under Objects and Timeline, right-click the element whose template you want to edit, point to Edit Control Parts (Template), and then click Edit Template.
  3. In the editing scope of the control template, delete the Border child element of the Grid.
  4. Double-click the Grid element to make it active so that you can add child elements.
  5. From the Toolbar, add three Grid controls Grid panel into the Grid of the template. You can add them quickly by double-clicking the Grid icon on the Toolbox, then right-clicking each Grid control under Objects and Timeline, pointing to Auto Size, and then clicking Fill.
  6. Right-click the ContentPresenter element, point to Order, and then click Bring to Front to layer the ContentPresenter in front of the new Grid objects.
  7. Under Objects and Timeline, rename the new grid objects to "Default", "Pressed", and "MouseOver" respectively, by right-clicking each object and then clicking Rename.
  8. To set up the trigger behavior, you need to make only one grid object visible per trigger. For example, with Default selected under Triggers in the Interaction panel, click the Pressed and MouseOver grid objects while holding down the CTRL key, to select those objects. Then, under Appearance in the Properties panel, set the Visibility property to Hidden.
  9. Click IsMouseOver = True under Triggers in the Interaction panel, select the Pressed and Default grid objects, and then under Appearance in the Properties panel, set the Visibility property to Hidden.
  10. Finally, with IsPressed = True selected under Triggers, select the MouseOver and Default grid objects, and then under Appearance in the Properties panel, set the Visibility property to Hidden.
  11. You can now design each grid object the way that you want it to appear under the different conditions. You can use Drawing tools and animation timelines to create unique behavior for your button. To design one of the grid objects without the others being visible, you can click the Hide/Show Hide/Show toggle button beside the other grid objects under Objects and Timeline.
  12. Test your application (F5) to see the effects.