我有一个动画移动的红色边框(带有RenderTransform),下面的蓝色边框处理MouseEnter事件。
不幸的是,当鼠标进入蓝色边框时(因为红色边框移开了)但鼠标移动时,MouseEnter不会被触发。
以下示例在Silverlight中进行了测试,但我相信在WPF中也是如此。
编辑:经过进一步测试后,这在WPF中有效。这是MrJul建议的错误还是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#代码
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();
}