tags:

views:

64

answers:

4

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

A: 

When a textbox is in a grid it gets its measures from the measures of the grid cell.

Svetlozar Angelov
+1  A: 

Hi AWC,

Viewbox is the easiest way:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  <Grid>  
  <Viewbox>
   <TextBlock Text="Hello World"/>
   </Viewbox>
  </Grid>
</Page>

Hope this helps,

Cheers, Anvaka

Anvaka
A: 

Did you try on TextBlock

VerticalAlignment="Stretch" HorizontalAlignment="Stretch"

Which is by default!

ArsenMkrt
A: 

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>
Malcolm