-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the problem this feature would solve
While developing apps for high-school physics students, I noticed that writing TextBlock content with multiple Runs with proper whitespace is a bit hard:
For example to output "(1,6×10^19)" I have to do:
<TextBlock>
<Run Text="(1,6×10" /><Run Text="⁻19" Typography.Variants="Superscript" /><Run Text=")" />
</TextBlock>
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 consecutive Runs.
Describe the solution
A solution similar to what is described in this blogpost with a small adjustment. Attached property TrimWhitespaceRuns on TextBlock would go through Runs and for all which havestring.IsNullOrWhitespace(Text) it would set their Text to string.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 skip Runs which have a Binding set for the Text property. A second attached property would allow preserving whitespace Run.
API
TextBox.TrimWhitespaceRunsPropertyRun.PreserveWhitespaceProperty
The above example would become:
<TextBlock toolkit:TextBlockExtensions.TrimWhitespaceRuns="true">
<Run Text="(1,6×10" />
<Run Text="⁻19" Typography.Variants="Superscript" />
<Run Text=")" />
</TextBlock>