开发者

Auto resizing font in WPF? [duplicate]

开发者 https://www.devze.com 2023-02-13 09:46 出处:网络
This question already has an answer here: 开发者_如何学Python Closed 10 years ago. Possible Duplicate:
This question already has an answer here: 开发者_如何学Python Closed 10 years ago.

Possible Duplicate:

WPF 4: Grow/Shrink TextBlock (Font Size) based on available space

I ma looking for a following behaviours in WPF: All the TextBlock in my app are shown in the 24 Font size, but if there isn't enough space I would to decrease a font size.

I thought of two solutions, but none of them work:

  1. Put a textBox inside viewbox. Doesn't work, as all labels start to get different sizes.
  2. If that would be a button I would specify a MinWidth instead of Width, but there is no property called MinFontSize on the TextBlock. Edit:
  3. Create a custom control with property MinTextWidth (this might work)

Any other solutions, which would work?


I would say this is a design issue, if the user can't see the entire item, shrinking the text will probably not help as it may make it unreadable.

You should think about doing something where either the TextBlock grows to fit the text, or your use an expander or something to allow them to see the rest of the text.


I think there isn't generic solution for this issue. There is one simple way: layout root for your window is ViewBox. Another way, by my opinion, is to write custom control and dynamically change ScaleTransform (not FontSize - this might causes perfomance issues).

0

精彩评论

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