29

私はWPFで遊び始めたばかりです。

Label のテキストのサイズまたは TextBlock のサイズ自体を親コンテナーに合わせることは可能ですか?

ありがとう、マーク

4

4 に答える 4

48

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>
于 2009-06-11T13:46:59.303 に答える
3

親コンテナに依存

Grid、DockPanel はコントロールをストレッチします。StackPanel、WrapPanel はコントロールに任せてサイズを調整します。

于 2009-06-11T13:34:07.150 に答える
1

Horizo​​ntalAlignment/VerticalAlignment を「ストレッチ」に設定します。

于 2009-06-11T13:30:57.250 に答える
0

DockPanel を親コンテナーとして使用する

<DockPanel>
  <TextBlock />
</DockPanel>
于 2009-06-11T13:28:53.933 に答える