[英]Right to left Marquee of text in wpf where width of text block is greater then Window without flickering
我正在使用以下代码进行动画处理(从右到左选取框):-
private void RightToLeftMarquee(TextBlock tb)
{
doubleAnimation = new DoubleAnimation();
doubleAnimation.From = -tb.Width;
doubleAnimation.To = TickerCanvas.Width;
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(100));
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Right)"));
sb.Children.Add(doubleAnimation);
sb.Begin(tb,true);
}
当文本块的宽度小于画布的宽度时,此代码可将文本块移至良好的位置,但是当文本块的宽度大于画布的宽度时,字幕将闪烁。
您看到的闪烁可能是由于ClearType子像素的位置。 您有几个选择,但是应用它们后,动画将看起来不那么平滑:
TextOptions.TextFormattingMode="Display"
这将打开较新的WPF 4.0 ClearType算法,这将使文本看起来更清晰。
UseLayoutRounding="True"
确保WPF使所有内容与设备像素对齐(不再有模糊的边框,图像等)
我总是在任何应用程序(即所有Window
)的根元素上使用这两种设置,因为它通常可以改善应用程序的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.