|
Este artículo se tradujo de forma manual. Mueva el puntero sobre las frases del artículo para ver el texto original.
|
Traducción
Original
|
UIElement.MouseEnter (Evento)
Ensamblado: PresentationCore (en PresentationCore.dll)
XMLNS para XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Invalide OnMouseEnter para implementar el control de clases para este evento en las clases derivadas.
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.
Nota |
|---|
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 Aplicar estilos y plantillas. |
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.
<StackPanel> <Border MouseEnter="OnMouseEnterHandler" MouseLeave="OnMouseLeaveHandler" Name="border1" Margin="10" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Center" Width="300" Height="100"> <Label Margin="10" FontSize="14" HorizontalAlignment="Center">Move Cursor Over Me</Label> </Border> </StackPanel>
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.
public partial class Window1 : Window { public Window1() { InitializeComponent(); } // raised when mouse cursor enters the area occupied by the element void OnMouseEnterHandler(object sender, MouseEventArgs e) { border1.Background = Brushes.Red; } // raised when mouse cursor leaves the area occupied by the element void OnMouseLeaveHandler(object sender, MouseEventArgs e) { border1.Background = Brushes.White; } }
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
Nota