使用 WPF 的平滑文本动画 (Marquee) [英] Smooth text animation (Marquee) using WPF
问题描述
尝试构建具有流畅文本动画的选取框控件.目前的努力包括:
Trying to build a marquee control with smooth text animation. Current efforts include:
- 使用翻译变换
- 在 Canvas 依赖属性(左、右)上使用动画
- 在自定义依赖属性(点)上使用动画并使用绘图视觉效果(格式化文本)
- 使用 CompositionTarget.Rendering
但动画仍然断断续续且占用大量资源(2-10% CPU).
But the animation is still choppy and resource intensive (2-10% CPU).
默认 wpf 窗口中使用的测试代码,我认为应该会产生平滑的动画:
Test code used in default wpf window which I assume should produce a smooth animation:
<TextBlock x:Name="_box" FontSize="64" CacheMode="BitmapCache" Text="lorem ipsum">
<TextBlock.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform" X="0" Y="0" />
</TextBlock.RenderTransform>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="AnimatedTranslateTransform"
Storyboard.TargetProperty="X"
From="-300" To="300" Duration="0:0:5"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
清单:
- 确认没有进行软件渲染(ms 性能工具并检查 RenderCapability.Tier)
- 对任何可以想象的对象调用冻结
- 禁用任何位图效果和透明度
- 检查了所有的选取框控件(相同的问题)
测试:
- CPU:Intell core 2 duo (T6600) @2.2Ghz
- 内存:4GB
- GPU:NVidia GeForce 9600M GS(最新驱动程序)
- 操作系统:Windows 7(64 位)
任何想法(或更好的代码示例)?
Any ideas (or better yet code example)?
从回复看来,这似乎不是 wpf 问题(其他选取框控件对其他人工作正常,但对我来说却不是),但是我在我测试过的每台机器上都遇到了同样的问题.
From the responses it seems this is not a wpf issue (other marquee controls work fine for others but not for me), nut I'm getting the same issues on every machine I tested this on.
推荐答案
希望可以帮到你 - http://jobijoy.blogspot.com/2008/08/silverlight-marquee-control.html
WPF 版本也可以在 这里找到
And the WPF version also can be found here
这篇关于使用 WPF 的平滑文本动画 (Marquee)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!