Search code examples
silverlightxamlmouseenter

MouseEnter event not fired during an animation


I have a red border moved by an animation (with a RenderTransform) and the blue border underneath is handling the MouseEnter event.

Unfortunately, the MouseEnter is not fired when the mouse enters the blue border (because the red border has moved away) but when the mouse is moved.

The sample below is tested in Silverlight but I believe the same happens in WPF.

EDIT: after further testing this works in WPF. Is this a bug as MrJul suggests or one of the "missing features" in Silverlight?

XAML

<Grid x:Name="borders" Width="40" Height="20">
    <Grid.Resources>
        <Storyboard x:Key="blueMove">
            <DoubleAnimation Duration="0:0:3" From="0" To="40" Storyboard.TargetName="redBorder"
                         Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"/>
        </Storyboard>
    </Grid.Resources>
    <Border Background="Blue" MouseEnter="Border_MouseEnter" />
    <Border x:Name="redBorder" Background="Red" MouseLeftButtonDown="Border_MouseLeftButtonDown">
        <Border.RenderTransform>
            <TransformGroup>
                <TranslateTransform Y="0"/>
            </TransformGroup>
        </Border.RenderTransform>
    </Border>
</Grid>

C# code behind

private void Border_MouseEnter(object sender, MouseEventArgs e)
{
 // Only called at the first MouseMove
}

private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
 (borders.Resources["blueMove"] as Storyboard).Begin();
}

Solution

  • This works fine in WPF but not in Silverlight so one would assume it's a possible bug in Silverlight. I'd suggest you fill an issue report on Connect.