我正在向 Canvas 添加多个用户控件。每个控件都有自己的 Storyboard,在加载时执行。我注意到它在执行 20 秒动画时非常不稳定。它并不是非常复杂,我希望有更好的性能。有什么我应该注意的问题吗?这是 Storyboard的示例:
<Storyboard x:Key="mystoryboard" RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(BlurEffect.Radius)" Storyboard.TargetName="itemgroup">
<SplineDoubleKeyFrame KeyTime="0" Value="30"/>
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:8" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:10" Value="30"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="itemgroup">
<SplineDoubleKeyFrame KeyTime="0" Value="0"/>
<SplineDoubleKeyFrame KeyTime="0:0:2" Value="0.96"/>
<SplineDoubleKeyFrame KeyTime="0:0:4" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:7" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:8" Value="1"/>
<SplineDoubleKeyFrame KeyTime="0:0:10" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="itemgroup">
<SplineDoubleKeyFrame KeyTime="0" Value="0.1"/>
<SplineDoubleKeyFrame KeyTime="0:0:10" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="itemgroup">
<SplineDoubleKeyFrame KeyTime="0" Value="0.1"/>
<SplineDoubleKeyFrame KeyTime="0:0:10" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="itemgroup">
<SplineDoubleKeyFrame KeyTime="0" Value="-60"/>
<SplineDoubleKeyFrame KeyTime="0:0:10" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
最佳答案
我注意到 Canvas 上形状相对简单的 Storyboard动画也存在类似情况。对我来说,DropShadowEffect 是罪魁祸首;删除阴影使动画变得平滑。您是否对用户控件应用了任何效果?
关于具有 Storyboard 动画的 WPF 用户控件不稳定/不稳定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5735466/