Reputation: 25631
How do I bind the height of TextBlock
to the height of the parent control?
I have a TextBlock
inside a grid and I want the TextBlock
Height
& Width
to be the height & width of the grid cell without hard coding the values.
Cheers
AWC
Upvotes: 0
Views: 3839
Reputation: 50712
Did you try on TextBlock
:
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Which is by default!
Upvotes: 0
Reputation: 1807
Here it is what u are looking for :
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="SelectedUserName" Grid.Row="0" Grid.Column="0" ></TextBlock>
</Grid>
Upvotes: 0
Reputation: 15823
Viewbox is the easiest way:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Viewbox>
<TextBlock Text="Hello World"/>
</Viewbox>
</Grid>
</Page>
Hope this helps,
Cheers, Anvaka
Upvotes: 2
Reputation: 21660
When a textbox is in a grid it gets its measures from the measures of the grid cell.
Upvotes: 0