web-dev-qa-db-ja.com

WPF / Silverlight XAMLストレッチテキストサイズをコンテナに合わせますか?

WPFで遊び始めたところです。

LabelのテキストのサイズまたはTextBlockのサイズ自体を、その親コン​​テナを満たすようにすることは可能ですか?

ありがとう、マーク

28
Mark

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

親コンテナに依存します

グリッド、DockPanelはコントロールStackPanelを拡大し、WrapPanelはそれ自体のサイズをコントロールに任せます。

3
Arcturus

Horizo​​nalAlignment/VerticalAlignmentを「stretch」に設定します。

1
Simon P Stevens

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

<DockPanel>
  <TextBlock />
</DockPanel>
0
Andrija