Forum Discussion

WPF_check's avatar
WPF_check
New Contributor
4 years ago

How could I get trimmed text from the 'TextBlock' WPF control ?

Hi all.


I have WPF control 'TextBlock' with TextTrimming="CharacterEllipsis"
When TextTrimming is set to CharacterEllipsis, the text is trimmed and continued with an 'ellipsis' at the character closest to the trimming edge.

 

All works fine, but how could I get trimmed text from the 'TextBlock' control?
All I can get is the initial text before the trimming, but I need the trimmed text, which could be seen by the end-user.

 

Example:

original text - "ThisIsLongText1234567890123456789======================"

trimmed text, visible for the user -"ThisIsLongText1234..."

I could get only original text from the Object Spy

 

 

Please, see attached picture and WPF code.

 

code:

 

<TextBlock
x:Name="TestTextBlock"
Grid.Row="0"
Width="150"
VerticalAlignment="Center"
Background="Chartreuse"
FontSize="16"
Text="ThisIsLongText1234567890123456789======================"
TextTrimming="CharacterEllipsis" />