[英]Make a TextBlock in a ScrollViewer Automatically Zoom to Fit
I'm creating a Windows 8 Metro app. 我正在创建Windows 8 Metro应用程序。 I have a
TextBlock
in a ScrollViewer
. 我在
ScrollViewer
有一个TextBlock
。 I'm wondering if it possible to programmatically change the ZoomFactor of the ScrollViewer
to make the TextBlock
auto-fit the width of the screen. 我想知道是否有可能以编程方式更改
ScrollViewer
的ZoomFactor以使TextBlock
自动适应屏幕的宽度。 Meaning, the longest line of the TextBlock
fit the screen width (without wrapping). 意思是,
TextBlock
的最长行适合屏幕宽度(不包含换行符)。
Generally I find ViewBox to be the most useful way to scale xaml contents to fit a predetermined size. 通常,我发现ViewBox是缩放xaml内容以适合预定大小的最有用方法。 Simply leave your ScrollViewer and TextBlock with no size requirements (and turn wrapping off) and then put the ScrollViewer inside a ViewBox with Scale=Uniform (or possibly UniformToFit depending on your needs).
只需将您的ScrollViewer和TextBlock保留为没有大小要求(然后关闭),然后将ScrollViewer放入Scale = Uniform(或视情况需要而定的UniformToFit)的ViewBox中。
The TextBlock will cause the ScrollViewer to size appropriately for its contents, and then the ViewBox will scale the ScrollViewer to exactly fit in its own control extents. TextBlock将导致ScrollViewer为其内容适当调整大小,然后ViewBox将缩放ScrollViewer以完全适合其自身的控制范围。 (Putting the ViewBox inside your root grid or as the root control of your page should cause it to fill the entire screen.)
(将ViewBox放在根网格中或作为页面的根控件应将其填满整个屏幕。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.