我刚开始玩WPF。
是否可以使用 Label 的文本大小或 TextBlock 大小本身来填充它的父容器?
谢谢,马克
您可以使用 ViewBox 以可视方式缩放某些内容以适应其容器。此处的其他解决方案有效,但它们仅拉伸控件,而不是其内容。ViewBox 将同时拉伸两者。
<!-- Big grid, will stretch its children to fill itself -->
<Grid Width="1000" Height="1000">
 <!-- The button is stretched, but its text remains teeny tiny -->
 <Button>
  <!-- The viewbox will stretch its content 
  to fit the final size of the button -->
  <Viewbox
      Margin="4"
      VerticalAlignment="Stretch"
      Height="Auto">
      <!-- The textblock and its contents are 
      stretched to fill its parent -->
      <TextBlock
          Text="Bartenders" />
  </Viewbox>
 </Button>
</Grid>
    取决于父容器
Grid,DockPanel 将拉伸您的控件 StackPanel,WrapPanel 会将其留给控件自行调整大小。
将 HorizonalAlignment/VerticalAlignment 设置为“拉伸”。
使用 DockPanel 作为父容器
<DockPanel>
  <TextBlock />
</DockPanel>