WPF automatic resize font until it fits within parent control

醉酒当歌 提交于 2020-01-22 06:58:30

问题


I have a user control who's root element is a Grid.

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.

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.

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.

Thank you

-Frinny


回答1:


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>


来源:https://stackoverflow.com/questions/14881683/wpf-automatic-resize-font-until-it-fits-within-parent-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!