[Feature] Extension to remove whitespace between TextBlock Runs #4656
Replies: 4 comments
-
Hello, 'MartinZikmund! Thanks for submitting a new feature request. I've automatically added a vote 👍 reaction to help get things started. Other community members can vote to help us prioritize this feature in the future! |
Beta Was this translation helpful? Give feedback.
-
I would be happy to implement this feature if it looks like a good fit :-) . |
Beta Was this translation helpful? Give feedback.
-
Thanks @MartinZikmund for highlighting the issue. Let's see what the other community members think and we can certainly move forward with this one. |
Beta Was this translation helpful? Give feedback.
-
@michael-hawker is this suitable for the toolkit? Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Describe the problem this feature would solve
While developing apps for high-school physics students, I noticed that writing
TextBlock
content with multipleRuns
with proper whitespace is a bit hard:For example to output "(1,6×10^19)" I have to do:
And this all has to be on a single line of XAML because whitespace between
Runs
generates a space in the output. This may result in long, hard to read lines of code for multiple consecutiveRuns
.Describe the solution
A solution similar to what is described in this blogpost with a small adjustment. Attached property
TrimWhitespaceRuns
onTextBlock
would go throughRuns
and for all which havestring.IsNullOrWhitespace(Text)
it would set theirText
tostring.Empty
. This way the runs stay there (in case someone the developer wanted to set them to something else later). It would also need to skipRuns
which have aBinding
set for theText
property. A second attached property would allow preserving whitespaceRun
.API
TextBox.TrimWhitespaceRunsProperty
Run.PreserveWhitespaceProperty
The above example would become:
Describe alternatives you've considered
Additional context & Screenshots
Beta Was this translation helpful? Give feedback.
All reactions