提高基本WPF故事板动画的流畅度

时间:2012-11-26 13:00:10

标签: wpf storyboard

我一直在玩一些基本的WPF Storyboard动画,它看起来很模糊,可以达到一定的速度然后真的降低到模糊度。

无论如何我能让它看起来更顺畅吗? - 以某种方式增加帧率或者可以双倍缓冲动画?

我已经尝试将对象设置为CacheMode =“BitmapCache”,但这似乎没什么效果。

有人有任何想法吗?

    <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>

1 个答案:

答案 0 :(得分:1)

您可以尝试增加FrameRate

MediaTimeline.DesiredFrameRateProperty.OverrideMetadata(typeof(System.Windows.Media.Animation.Timeline), new FrameworkPropertyMetadata(60));

数字越大,帧速率越高(执行越平滑)。但要小心,更高的帧速率会影响性能!

我希望这会有所帮助。