I want to stretch the text in WPF Textblock with out changing the font size of the textblock?
Text stretch in WPF TextBlock
Asked Answered
If you want a 'stretch to fit' type of behavior, check out ViewBox. –
Eclat
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>
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>
© 2022 - 2024 — McMap. All rights reserved.