Text Stretch in WPF TextBlock

I want to stretch text in WPF Textblock without changing the font size of the text block?

+3
source share
2 answers

use layout or visualization to scale text in the X or Y direction depending on what you want

LayoutTransform forces the scale to be applied before passing the layout, which means that the element is rendered with the scaled size taken for the account. Taking into account that RenderTransform applies scaling after passing the layout so that the element is at a normal level, then the scale is applied.

Sort of

<TextBlock Text="Foo">
  <TextBlock.RenderTransform>
    <ScaleTransform ScaleX="2" ScaleY="2" />
  </TextBlock.RenderTransform>
</TextBlock>
+4
source

, ViewBox Layout Transform:

<DockPanel>
  <Viewbox>
    <Viewbox.LayoutTransform>
      <ScaleTransform CenterX="50" ScaleX="0.5" />
    </Viewbox.LayoutTransform>
    <TextBlock Text="Some random text."  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
  </Viewbox>
</DockPanel>
+3

All Articles