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开发者_JAVA技巧
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
When a textbox is in a grid it gets its measures from the measures of the grid cell.
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>
Did you try on TextBlock
:
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Which is by default!
精彩评论