You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While developing apps for high-school physics students, I noticed that writing TextBlock content with multiple Runs with proper whitespace is a bit hard:
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.
Describe the problem this feature would solve
While developing apps for high-school physics students, I noticed that writing
TextBlockcontent with multipleRunswith 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
Runsgenerates 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
TrimWhitespaceRunsonTextBlockwould go throughRunsand for all which havestring.IsNullOrWhitespace(Text)it would set theirTexttostring.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 skipRunswhich have aBindingset for theTextproperty. A second attached property would allow preserving whitespaceRun.API
TextBox.TrimWhitespaceRunsPropertyRun.PreserveWhitespacePropertyThe above example would become:
Describe alternatives you've considered
Additional context & Screenshots