如何设置TextBlock高度

时间:2010-02-18 14:21:12

标签: wpf xaml height textblock

如何将TextBlock的高度绑定到父控件的高度?

我在网格中有TextBlock,我想要TextBlock Height& Width成为身高&网格单元格的宽度,无需对值进行硬编码。

干杯

AWC

4 个答案:

答案 0 :(得分:2)

Viewbox是最简单的方式:

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

希望这有帮助,

干杯,安瓦卡

答案 1 :(得分:0)

当文本框位于网格中时,它会从网格单元格的度量中获取度量值。

答案 2 :(得分:0)

你试过TextBlock

VerticalAlignment="Stretch" HorizontalAlignment="Stretch"

默认情况下!

答案 3 :(得分:0)

这就是你要找的东西:

<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>
相关问题