如何将高度绑定TextBlock
到父控件的高度?
我有TextBlock
一个网格内部,我希望TextBlock
Height
&Width
成为网格单元格的高度和宽度,而无需对值进行硬编码。
干杯
AWC
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>
希望这可以帮助,
干杯,安瓦卡
这就是你要找的东西:
<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>
当文本框位于网格中时,它会从网格单元格的度量中获取其度量。
你试穿了吗TextBlock
:
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
默认情况下!