Improve the smoothness of a basic WPF storyboard animation

╄→гoц情女王★ 提交于 2019-12-08 06:45:24

问题


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?

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>

回答1:


You could try increasing the 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!

I hope this helps.



来源:https://stackoverflow.com/questions/13565368/improve-the-smoothness-of-a-basic-wpf-storyboard-animation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!