Reputation: 3773
I want to have a TextBlock element that contains two seperate strings, both in a single line. One is aligned to the left edge of the TextBlock, one to the right edge.
In HTMl&CSS I would do it like this:
<div id="TextBlock">
<span style="float:left;display:block">align:left</span>
<span style="float:right;display:block">align:right</span>
<span style="clear:both"></span>
</div>
Here both Texts align:right and align:left are shown in the same line.
Is there a possibility to do this in XAML as well?
Upvotes: 1
Views: 1218
Reputation: 3773
jv42's comment-answer worked fine for me:
Have you tried? If you put two TextBlocks into a Grid container with the text alignment you want, it should work. – jv42
Upvotes: 0
Reputation: 8126
Put TextBlocks
inside a Grid
control into different Columns
. You must specify how TextBlocks
will trim if Grid
width is less that TextBlocks
total width. Set Auto
, *
or number*
for this in different combinations:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="text1" TextAlignment="Left" />
<TextBlock Grid.Column="1" Text="text2" TextAlignment="Right" />
</Grid>
Upvotes: 3