Reputation: 3180
Consider the following XAML:
<Grid>
<TextBlock Text="Some Text" TextAlignment="Right" />
<TextBlock Text="Some Text" HorizontalAlignment="Right" />
</Grid>
So long as both TextBlock
s are set to the same Grid.Row
and Grid.Column
, they will always appear in the same place - one on top of the other.
Similar concept, here - with the 2 lines of text in both the StackPanel
s aligning exactly:
<Grid>
<StackPanel>
<TextBlock Text="Line One" HorizontalAlignment="Right" />
<TextBlock Text="Line Two" TextAlignment="Right" />
</StackPanel>
<StackPanel>
<TextBlock Text="Line One" HorizontalAlignment="Right" />
<TextBlock Text="Line Two" TextAlignment="Right" />
</StackPanel>
</Grid>
And so on...
In terms of displaying the text to the right of the parent, the TextAlignment
and HorizontalAlignment
attributes are both doing the same thing - from what I can see.
Can anybody tell me what the actual difference between TextAlignment
and HorizontalAlignment
is, when it comes to TextBlock
s?
Is there a preferred choice of the two to use?
Are there any implications to using either?
Upvotes: 5
Views: 4770
Reputation: 37059
HorizontalAlignment
determines the alignment of the TextBox
relative to its parent.
TextAlignment
determines the alignment of the text within the TextBox
Upvotes: 5