WPF动画不平滑

本文关键字:平滑 动画 WPF | 更新日期: 2023-09-27 18:20:52

我正试图在WPF中制作一个简单的关门动画,但无法使其流畅——它太不稳定了。

亲自查看

以下是显示问题的视频截图:

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

死胡同

  • 我试着把画笔换成纯色,但仍然不稳定
  • 减慢动画的持续时间-仍然不平滑
  • 将DesiredFrameRate设置为较低值或较高值没有帮助
  • 放松功能似乎也没有帮助
  • 这个问题可能只出现在高清显示器上(我正在测试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>

WPF动画不平滑

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