问题描述
我有一个用户控件,其根元素是网格.
I have a user control who's root element is a Grid.
我还有一个ContentControl,它用作加载数据时填充的某些文本的占位符.该控件可以在用户控件内移动,因此它的位置可以在任何地方.
I also have have a ContentControl that serves as a placeholder for some text that is filled when data is loaded. This control can be moved around within the user control and so it's position can be anywhere.
如果文本太长而无法容纳在用户控件的根Grid中,我想减小ContentControl的字体大小,直到文本适合为止.
If the text is too long to fit within the root Grid of the user control, I want to reduce the font size of the ContentControl until the text fits.
我的问题是我似乎找不到可以处理的事件.我尝试使用ContentControl.LayoutUpdated事件;但是,该事件的sender参数始终显示为空……这真的没有帮助!
My problem is that I can't seem to find an event that I can handle to do this process.I tried using the ContentControl.LayoutUpdated event;however, the sender parameter for this always appears to be nothing...which is really not helpful!
我真的很期待关于如何实现这一目标的任何建议.
I am really looking forward to any advise on how to achieve this.
谢谢
-Frinny
推荐答案
将ContentControl
包装为仅按比例缩小的Viewbox
会为您完成:
Wrapping your ContentControl
in a Viewbox
set to only scale down will do this for you:
<Viewbox StretchDirection="DownOnly" Stretch="Uniform">
<ContentControl Content="Some Text"/>
</Viewbox>
这篇关于WPF自动调整字体大小,直到适合父控件为止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!