2011-06-08 84 views
3

我想要擴展WPF文本塊中的文本而不更改文本塊的字體大小?在WPF文本塊中的文本拉伸

+0

如果你想有一個「拉伸,以適應」類型的行爲,看看ViewBox。 – 2011-06-08 18:04:05

回答

4

使用佈局或呈現轉化爲規模在X或取決於你想要什麼

LayoutTransform導致規模Y方向文本之前的佈局傳遞,這意味着元素呈現與縮放到應用大小採取帳戶。而RenderTransform在佈局過後應用縮放,因此元素以正常大小間隔,然後應用比例。

喜歡的東西

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

伸展文本在整個控制並使其更窄,我使用視框和佈局轉換:

<DockPanel> 
    <Viewbox> 
    <Viewbox.LayoutTransform> 
     <ScaleTransform CenterX="50" ScaleX="0.5" /> 
    </Viewbox.LayoutTransform> 
    <TextBlock Text="Some random text." HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
    </Viewbox> 
</DockPanel>