我有 ToggleButton
并应用了 OuterGlowBitmapEffect
。我对这种发光进行动画处理,使其具有脉动效果,吸引人们的注意力。我的问题是,如果我将动画放慢一秒钟,它就会卡顿很多。如何防止出现卡顿现象?是什么原因导致卡顿不流畅?
这是按钮:
<ToggleButton x:Name="btnMap1" Click="btnMap1_Click" Style="{DynamicResource GenericButton}" Width="152" Height="127" IsChecked="True">
<ToggleButton.BitmapEffect>
<OuterGlowBitmapEffect GlowColor="White" GlowSize="0" Noise="0" Opacity="1" />
</ToggleButton.BitmapEffect>
</ToggleButton>
这是动画:
<Storyboard x:Key="ButtonGlow" RepeatBehavior="Forever" Timeline.DesiredFrameRate="30">
<DoubleAnimation
BeginTime="00:00:00"
Storyboard.TargetName="btnMap1"
Storyboard.TargetProperty="(UIElement.BitmapEffect).(OuterGlowBitmapEffect.GlowSize)"
From="0.0"
To="10.0"
Duration="0:0:1"
AutoReverse="True"
/>
</Storyboard>
最佳答案
此效果非常消耗 CPU 资源,因为它是软件渲染的而不是 GPU 生成的。
Microsoft has deprecated this and similar effects and discourages their use .
Bitmap effects should not be applied to large visuals or animations because this can degrade performance.
他们建议使用BlurEffect
相反。
关于.net - 使用 WPF 在外发光上实现平滑动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3368234/