提高基本 WPF 故事板动画的流畅度 [英] Improve the smoothness of a basic WPF storyboard animation
问题描述
我一直在玩一些基本的 WPF Storyboard 动画,它看起来很模糊,在达到一定速度后还可以,然后真的降级为模糊.
I've been playing around with some basic WPF Storyboard animation and it looks quite blurry, it's Ok up to a certain speed then really degrades into blurryness.
无论如何我可以让它看起来更平滑吗?- 以某种方式提高帧率或者双缓冲动画?
Is there anyway I can get it to look smoother? - increase the framerate somehow or maybe double buffer the animation?
我已经尝试将对象设置为 CacheMode="BitmapCache" 但这似乎没什么效果.
I've tried setting the objects to CacheMode="BitmapCache" but this seems to have little effect.
请问大家有什么想法吗?
Does anyone have any ideas please?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Width="1000" Height="600" >
<Window.Triggers>
<EventTrigger RoutedEvent="UserControl.Loaded" >
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation From="600" To="-600" Duration="00:00:02"
Storyboard.TargetName="MyObject"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid>
<Grid Name="MyObject">
<Grid.RenderTransform>
<TranslateTransform X="0" />
</Grid.RenderTransform>
<Ellipse Stroke="Black" Fill="Green" StrokeThickness="3" Width="100" Height="250" />
<Ellipse Stroke="Black" Fill="White" StrokeThickness="3" Width="80" Height="180" />
</Grid>
</Grid>
</Window>
推荐答案
您可以尝试增加 FrameRate
:
MediaTimeline.DesiredFrameRateProperty.OverrideMetadata(typeof(System.Windows.Media.Animation.Timeline), new FrameworkPropertyMetadata(60));
数字越大,帧率越高(执行越流畅).不过要小心,更高的帧率会影响性能!
The higher the number, the higher the framerate (the smoother the execution). Be cautious though, higher framerates impact performance!
我希望这会有所帮助.
这篇关于提高基本 WPF 故事板动画的流畅度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!