简体   繁体   中英

Change font size to fit textblock

I'm having a little problem, i have Custom list box item, that is 165 px height. So, the text block wraps text and gets 50% height of the list box item, example:

例

How you noticed the text size is too big.

Is there a way to make fint size exatly big to fit in the textblock?

As far as my understanding it can be done with help of textBox.Text.Length property. Also It depends on the font you are using.

What happens when the Text is 10000 characters long? Rather than trying to show all of the text you should make the font smaller (no need for something that large) and use TextTrimming . TextTrimming will cut the text short and put an ellipse at the end.

<TextBlock Text="{Binding MyProperty}" TextTrimming="WordEllipsis" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM