WPF动画不流畅

时间:2014-09-05 17:50:19

标签: c# .net wpf performance animation

我试图在WPF中制作一个简单的关门动画,但不能让它变得流畅 - 它太生涩了。

亲自看看

这是一个显示问题的视频截屏视频:

https://www.dropbox.com/s/97qdnhk2w6jbi5s/wpf-animation-not-smooth.mp4?dl=0

死角

  • 我试图将画笔替换为纯色,但仍然不稳定
  • 减慢动画的持续时间 - 仍然不顺畅
  • 将DesiredFrameRate设置为a lower valueto a higher value无效
  • Easing functions似乎没有任何帮助
  • 问题可能只出现在高清显示器上(我在1920x1200上进行测试)?

XAML尝试

<Window x:Class="Smth.ShellView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            WindowState="Maximized"
            AllowsTransparency="True"
            ResizeMode="NoResize"                      
            Topmost="True"
            WindowStyle="None"
            MinWidth="{Binding Source={x:Static SystemParameters.FullPrimaryScreenWidth}}"
            MinHeight="{Binding Source={x:Static SystemParameters.FullPrimaryScreenHeight}}"                
            x:ClassModifier="internal"  >
<Window.Background>
    <SolidColorBrush Opacity="0" Color="White"/>
</Window.Background>
<Window.Triggers>
    <EventTrigger
  RoutedEvent="Window.Loaded">
        <BeginStoryboard>
            <Storyboard BeginTime="0:0:3">                    
                <DoubleAnimation Storyboard.TargetName="leftDoorMove" Storyboard.TargetProperty="X" To="0" Duration="0:0:6" >
                </DoubleAnimation>
                <DoubleAnimation Storyboard.TargetName="rightDoorMove" Storyboard.TargetProperty="X" To="0" Duration="0:0:6" >
                </DoubleAnimation>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>
    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
    <Border x:Name="leftDoor" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
        <Border.Background>
            <LinearGradientBrush>
                <GradientStop Color="Yellow" Offset="0.0" />
                <GradientStop Color="Red" Offset="0.25" />
                <GradientStop Color="Blue" Offset="0.75" />
                <GradientStop Color="LimeGreen" Offset="1.0" />
            </LinearGradientBrush>
        </Border.Background>
        <Border.RenderTransform>
            <TranslateTransform x:Name="leftDoorMove" X="-950" />
        </Border.RenderTransform>
    </Border>
    <Border x:Name="rightDoor" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
        <Border.Background>
            <LinearGradientBrush>
                <GradientStop Color="Yellow" Offset="0.0" />
                <GradientStop Color="Red" Offset="0.25" />
                <GradientStop Color="Blue" Offset="0.75" />
                <GradientStop Color="LimeGreen" Offset="1.0" />
            </LinearGradientBrush>
        </Border.Background>
        <Border.RenderTransform>
            <TranslateTransform x:Name="rightDoorMove"  X="950"  />                
        </Border.RenderTransform>
    </Border>
</Grid>          
</Window>

1 个答案:

答案 0 :(得分:0)

要尝试的另一件事是将缩放设置为低质量。 RenderOptions.SetBitmapScalingMode(imageObject,BitmapScalingMode.LowQuality);

相关问题