Reputation: 8903
if i have a textblock which i want to vary in width by the size of its contents, but i want the left of the textblock to maintain a certain spacing from the right of the container... how is this accomplished? I feel I'm overlooking something simple. Im specifically using WPF, if that matters.
Upvotes: 2
Views: 971
Reputation: 189487
The solution would be to place the TextBlock inside a StackPanel
like this:-
<StackPanel HorizontalAlighment="Right" Width="200">
<TextBlock Text="Some Text or binding" />
</StackPanel>
Where Width 200 represents the fixed distance you want the left border of the TextBlock
to be away from the right border of the element containing the StackPanel
.
Upvotes: 2
Reputation: 3777
Try the HorizontalAlignment
property.
HorizontalAlignment="Right"
<Grid x:Name="LayoutRoot" Background="Yellow">
<StackPanel
Background="AliceBlue"
Margin="50">
<TextBlock
Text="Some text"
HorizontalAlignment="Right"/>
<TextBlock
Text="Some other longer text"
HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
Produces this output:
Upvotes: 0