开发者

How to grow/shrink a TextBlock (Font Size) to the available space in WPF?

开发者 https://www.devze.com 2023-02-06 10:16 出处:网络
I\'ve seen this question asked a lot, however, to the opposite of what I\'m looking for.While other people want a control to size itself based on the开发者_开发百科 size of text, I\'m trying to figure

I've seen this question asked a lot, however, to the opposite of what I'm looking for. While other people want a control to size itself based on the开发者_开发百科 size of text, I'm trying to figure out is if there is a way to grow the size of text to the amount of space available.

Take the idea of a digital clock window and you want the numbers stating the time to grow (or shrink) based on the size of the window the clock is in. If there isn't a way to automatically do this any pointers to a programmatic way I can get this accomplished?


The WPF Viewbox control will grow / shrink its contents to the available space:

http://www.wpftutorial.net/ViewBox.html

Just place your TextBlock within a ViewBox:

<Viewbox Stretch="Uniform" Width="50" Height="50">
    <TextBlock Text="Test" />
</Viewbox>

Of course, your Viewbox is typically scaled by its container, but hopefully you get the idea!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号