Text stretch in WPF TextBlock

寵の児 提交于 2019-12-10 16:45:16

问题


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


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/6282134/text-stretch-in-wpf-textblock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!