Search code examples
wpftextformattingtextblock

Text stretch in WPF TextBlock


I want to stretch the text in WPF Textblock with out changing the font size of the textblock?


Solution

  • use a layout or render transform to scale your text in the X or Y direction depending on what you want

    LayoutTransform causes the scale to be applied prior to the layout pass which means the element is rendered with the scaled size taken in to account. Whereas the RenderTransform applies the scaling after the layout pass so the element is spaced at normal size then the scale is applied.

    Something like

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