I want to handle mouse over and mouse out events for a grid. Does WPF have events for this. Note: I dont want to use IsMouseOver property in my style. i have used MouseEnter and MouseLeave method but without much success.
A:
You can use EventTriggers to capture MouseEnter and MouseLeave events in XAML.
Here is a simple example that changes the background of a StackPanel in a Grid:
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Background="Blue">
<StackPanel.Style>
<Style>
<Style.Triggers>
<EventTrigger RoutedEvent="StackPanel.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation
AutoReverse="False"
Duration="0:0:1"
From="Blue" To="Red"
AccelerationRatio="1"
Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)"
FillBehavior="HoldEnd">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="StackPanel.MouseLeave">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation
AutoReverse="False"
Duration="0:0:1"
From="Red" To="Blue"
AccelerationRatio="1"
Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)"
FillBehavior="HoldEnd">
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
</StackPanel>
</Grid>
Zamboni
2010-09-17 15:29:06
A:
A WPF Grid control supports both the MouseEnter
and MouseLeave
events. You should be able to hook up event handlers for both.
Eric
2010-09-17 15:55:00
A:
MouseEnter and MouseLeave events may be handled , you can check your code set e.handled = flase;
Park Wu
2010-09-19 03:31:37