I want to stretch the text in WPF Textblock with out changing the font size of the textblock?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With