cancel
Showing results for 
Search instead for 
Did you mean: 

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

WPF_check
New Contributor

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

 

001.png

 

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" />

 

 

4 REPLIES 4
ebarbera
Staff

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

Hi @WPF_check - 

 

I would try using custom attributes to gain access to the trimmed text - here is the link with additional information : https://support.smartbear.com/testcomplete/docs/app-testing/web/general/object-identification/using-...

 

Let me know if you have any questions. 

 

Emma

AlexKaras
Community Hero

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

Hi,

 

If no relevant property provided by TestComplete can be found in the Object Browser, I would talk to developers and ask what native property/method can be used to get trimmed text. With a high probability this property/method should be accessible from TestComplete so you should be able to use it in your test code.

https://support.smartbear.com/testcomplete/docs/app-testing/desktop/wpf/accessing-native-members.htm...

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
WPF_check
New Contributor

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

Hi Alex,

 

Thanks for your response.

The main issue is that I have written this code.
WPF process 'text trimming' under the hood and there is no method to get the value of the trimmed string.
Maybe, I could talk with the ObjectSpy or Testcomplete-core developer about this?

 

Do you know any person to mention here?

AlexKaras
Community Hero

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

Hi,

 

there is no method to get the value of the trimmed string.

If trimmed text is just rendered on screen without been accessible via some method or property then you may try text recognition in TestComplete: https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/text-recognition/...

Support can be contacted via the https://support.smartbear.com/testcomplete/message/ form.

 

P.S. If the code to create trimmed text is under your control, isn't it more easy and reliable for testing to keep trimmed text in some property accessible to TestComplete?

https://support.smartbear.com/testcomplete/docs/app-testing/desktop/wpf/about.html#AvailableProperti...

 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors