我有一个带有 KeyFrameAnimation 淡入效果的窗口
<Storyboard x:Key="FadeIn">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="window" Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.8" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard x:Name="BusyAnimation_BeginStoryboard" Storyboard="{StaticResource FadeIn}" />
</EventTrigger>
</Window.Triggers>
在后面的代码中,我正在处理 MouseEnter 和 MouseLeave:
private void FancyNotificationView_OnMouseEnter(object sender, MouseEventArgs e)
{
SetValue(Window.OpacityProperty, 1.0);
Debug.WriteLine((double) GetValue(Window.OpacityProperty));
}
private void FancyNotificationView_OnMouseLeave(object sender, MouseEventArgs e)
{
SetValue(Window.OpacityProperty, 0.8);
}
只要触发器处于活动状态,这将不起作用。不知何故,动画阻碍了我手动设置这些属性。如何保持动画并让 MouseEnter 和 MouseLeave 以我想要的方式运行?