Create a Rollover Effect Using Events

How to: Create a Rollover Effect Using Events

 

This example shows how to change the color of an element as the mouse pointer enters and leaves the area occupied by the element.

This example consists of a Extensible Application Markup Language (XAML) file and a code-behind file.

System_CAPS_noteNote

This example demonstrates how to use events, but the recommended way to achieve this same effect is to use a Trigger in a style. For more information, see Styling and Templating.

Example

The following XAML creates the user interface, which consists of Border around a TextBlock, and attaches the MouseEnter and MouseLeave event handlers to the Border.

The following code behind creates the MouseEnter and MouseLeave event handlers. When the mouse pointer enters the Border, the background of the Border is changed to red. When the mouse pointer leaves the Border, the background of the Border is changed back to white.

     

Show:
© 2016 Microsoft