Answered by:
TextWrapping in the middle of a String

Question
-
I have a TextBlock whose Text property gets assigned a very long String. When this TextBlock is displayed, I want it to display as many characters as possible on each line before wrapping to the next line, regardless of what they are. I set the TextWrapping property to Wrap, but it still seems to be using some kind of algorithm to choose where the line wraps. Is there any way to prevent the TextBlock from wrapping until the end of the line is reached? Basically, I don't want to see any whitespace. Thanks.
Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
Tuesday, December 9, 2014 1:19 AM
Answers
-
Hi Nathan,
Per my understanding, we can use another easy way to work around. Create a custom TextBlock inherit the build-in one, add one property like “RealText”. This property stores the whole URL like “https://social.msdn.microsoft.com/Forums/en-US/8e3697dc-6601-480c-a4e6-a2791acb58da/textwrapping-in-the-middle-of-a-string?forum=winappswithcsharp”, and the original Text property stores string like “https://social.msdn.microsoft.com/Forums/......../textwrapping-in-the-middle-of-a-string?forum=winappswithcsharp”. When you need to access the URL, just get value from RealText property.
Hope can give you some inspiration.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Monday, December 22, 2014 1:31 AM
Tuesday, December 16, 2014 1:48 AMModerator
All replies
-
Hi,
Have you tried this
<TextBlock Name="textBlock1" >line 1 <LineBreak /> line 2</TextBlock>
-Malleswar
Tuesday, December 9, 2014 1:26 AM -
That is not my situation. The Text property of my TextBlock is databound, there are no linebreaks in the value assigned to it.
Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
Tuesday, December 9, 2014 1:36 AM -
Hi Nathan,
As I know, the TextBlock control use the wrap property to render the text in new line and will not split the single word. Does you need split the word when reaches the end of a line? If so, I think you should write your own algorithm to split your word at runtime. But this approach is more complex. Is this exactly you want?
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
Friday, December 12, 2014 3:39 AMModerator -
I think so, yes. What I am displaying is a URL, so the TextBlock could end up wrapping it at many different points, making some lines very short, and others take most of the line, causing there to be a lot of wasted space and look very ugly.
Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
Friday, December 12, 2014 4:03 AM -
Hi Nathan,
Per my understanding, we can use another easy way to work around. Create a custom TextBlock inherit the build-in one, add one property like “RealText”. This property stores the whole URL like “https://social.msdn.microsoft.com/Forums/en-US/8e3697dc-6601-480c-a4e6-a2791acb58da/textwrapping-in-the-middle-of-a-string?forum=winappswithcsharp”, and the original Text property stores string like “https://social.msdn.microsoft.com/Forums/......../textwrapping-in-the-middle-of-a-string?forum=winappswithcsharp”. When you need to access the URL, just get value from RealText property.
Hope can give you some inspiration.
Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Monday, December 22, 2014 1:31 AM
Tuesday, December 16, 2014 1:48 AMModerator