#843 – Text Justification in a TextBlock

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).

WPF allows justification of text using the TextBlock element.  You specify justification in a TextBlock using the TextAlignment property, setting it to one of: Left, Right, Center or Justify.

        <TextBlock Text="{StaticResource someText}"
                   TextWrapping="Wrap"
                   TextAlignment="Left"
                   Margin="10"/>
        <TextBlock Text="{StaticResource someText}"
                   TextWrapping="Wrap"
                   TextAlignment="Right"
                   Margin="10"/>
        <TextBlock Text="{StaticResource someText}"
                   TextWrapping="Wrap"
                   TextAlignment="Center"
                   Margin="10"/>
        <TextBlock Text="{StaticResource someText}"
                   TextWrapping="Wrap"
                   TextAlignment="Justify"
                   Margin="10"/>

843-001

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

One Response to #843 – Text Justification in a TextBlock

  1. Pingback: Dew Drop – June 17, 2013 (#1,569) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: