I'm using WPF's TextBlock
for running text animation. I do so by setting the TranslateTransform.X
from -ActualWidth
to ActualWidth
.
Everything works fine but there is one little problem: The text in the TextBlock.Text
property is trimmed to fit the initial size window.
<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 (...).
I would like to know how can I replace these three dots with the full text (no trimming text).
I'm assuming the size of your TextBlock
is being constrained by its parent container. Wrapping it in a Canvas
should 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
.
As an aside, there are some attached properties in TextOptions
that you might want to look at if you will be drawing animated text, eg, TextHintingMode
.
If you don't want the TextBlock
to trim text, then don't set 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 TextBlock
will be replaced with an ellipsis, "...".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.