【问题标题】:WPF Animation Not SmoothWPF动画不流畅
【发布时间】:2014-10-30 17:31:23
【问题描述】:

我正在尝试在 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>

【问题讨论】:

  • Cel,你的动画在我的机器上运行得非常流畅。我想知道您的计算机是否不让硬件处理动画?
  • 您的视频在背景中显示图像,我在 xaml 中没有看到。您的窗口上还有一个透明背景。你试过没有这些跑步吗?如果图像需要缩放会影响重绘,即使不透明度为 0,它仍然会添加到具有背景的绘制过程中。否则,请注意可能影响您机器性能的其他进程。
  • @kidshaw 背景中的图像是 Windows 桌面壁纸 :) 当我禁用透明背景并让它只是白色时,不幸的是没有性能提升:(
  • 对,现在说得通了。老实说,这听起来好像是本地机器性能问题。我在这里看不到任何应该导致这种情况的东西。

标签: c# .net wpf performance animation


【解决方案1】:

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

【讨论】:

  • 在我提供的 XAML 中我应该使用什么作为 imageObject,我应该在哪里设置这个缩放比例?
  • 另外,我在另一台非高清显示器的 PC 上尝试了这个示例应用程序,虽然它稍微平滑一些,但你可以看到“门”仍然短暂地停止/闪烁有几次 - 动画一路不流畅,我不是完美主义者..
猜你喜欢
  • 1970-01-01
  • 2017-03-02
  • 2010-11-07
  • 2017-07-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-17
  • 2018-07-28
  • 2015-11-28
相关资源
最近更新 更多