Text stretch in WPF TextBlock
Asked Answered
A

2

5

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

Aloin answered 8/6, 2011 at 16:31 Comment(1)
If you want a 'stretch to fit' type of behavior, check out ViewBox.Eclat
P
7

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>
Participial answered 8/6, 2011 at 16:45 Comment(0)
D
4

To stretch text over the entire control and make it narrower, I use ViewBox and 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>
Debbradebby answered 14/6, 2011 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.