WPF 文本修剪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26427151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Text Trimming
提问by Jacob
I'm using WPF's TextBlockfor running text animation.
I do so by setting the TranslateTransform.Xfrom -ActualWidthto ActualWidth.
我正在使用 WPFTextBlock来运行文本动画。我通过设置TranslateTransform.Xfrom-ActualWidth来做到这一点ActualWidth。
Everything works fine but there is one little problem:
The text in the TextBlock.Textproperty is trimmed to fit the initial size window.
一切正常,但有一个小问题:TextBlock.Text属性中的文本被修剪以适合初始大小的窗口。
<TextBlock x:Name="txtRunning"
TextWrapping="NoWrap"
VerticalAlignment="Center"
TextTrimming="WordEllipsis"
Text="very long text here...">
I tried to set: TextTrimming="WordEllipsis"but it replaced the trimming with three dots (...).
我试图设置:TextTrimming="WordEllipsis"但它用三个点(...)代替了修剪。
I would like to know how can I replace these three dots with the full text (no trimming text).
我想知道如何用全文(无修剪文本)替换这三个点。
回答by Mike Strobel
I'm assuming the size of your TextBlockis being constrained by its parent container. Wrapping it in a Canvasshould allow it to extend beyond the right edge of the window and give you the scrolling banner effect you want. That should be the only change necessary; you would still apply the animated transform directly to the TextBlock.
我假设您的大小TextBlock受到其父容器的限制。将它包裹在 a 中Canvas应该允许它超出窗口的右边缘,并为您提供所需的滚动横幅效果。那应该是唯一必要的改变;您仍然可以将动画变换直接应用于TextBlock.
As an aside, there are some attached properties in TextOptionsthat you might want to look at if you will be drawing animated text, e.g., TextHintingMode.
顺便说一句,TextOptions如果要绘制动画文本,您可能需要查看一些附加属性,例如TextHintingMode.
回答by Sean Cogan
If you don't want the TextBlockto trim text, then don't set TextTrimming:
如果您不想TextBlock修剪文本,则不要设置TextTrimming:
<TextBlock x:Name="txtRunning" TextWrapping="NoWrap" VerticalAlignment="Center" Text="very long text here...">
Setting TextTrimming="WordEllipsis"means that any text that doesn't fit within the TextBlockwill be replaced with an ellipsis, "...".
设置TextTrimming="WordEllipsis"意味着任何不适合的文本TextBlock都将替换为省略号“...”。

