#942 – Text Justification in a TextBox
November 4, 2013 Leave a comment
In typography, justification is the alignment of the edges of a block of text. Text can be “flush left”, indicating that the left edges of the lines are aligned with each other and the right edges are ragged–i.e. not aligned. Text can also be “flush right” (right ends of lines are aligned), “justified” (both edges line up), or centered (both edges ragged).
Like the TextBlock, the TextBox control allows setting justification using the TextAlignment property. When set, text is continually adjusted to fulfill the desired alignment, as the user types.
- Left – Left justify the text (default)
- Right – Right justify the text
- Center – Center the text
- Justify – Insert spaces between words to line up both edges of text (only takes effect if line fills up available width and then wraps)
<TextBox Margin="5" Height="100" TextAlignment="Center" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto"/>