C#WPF拉伸/缩放窗口与大小成比例

[英]C# WPF Stretching/scaling window proportional to size


I am aware of the FontStretch property, but not really sure how to use it.

我知道FontStretch属性,但不确定如何使用它。

What I want is to create a window designed with a resolution of say 200x400. Then when the user stretches it to 400x800 (or whatever), I'd just like the entire window to stretch/scale up (in the given scenario, everything would double in size) rather than just moving around. It would be nice if it worked with images as well, but just getting the fonts and general object sizes to do this would be good.

我想要的是创建一个分辨率为200x400的窗口。然后,当用户将其拉伸到400x800(或其他)时,我只想整个窗口伸展/放大(在给定的场景中,一切都会增加一倍),而不是仅仅四处移动。如果它也适用于图像会很好,但只需获取字体和一般对象大小就可以了。

Are there any inbuilt functions or 3rd party libraries that provide this functionality?

是否有任何内置函数或第三方库提供此功能?

2 个解决方案

#1


4  

If all your content has to be stretched proportionally including texts, controls and images, fix your main panel size to 200x400 and include it in a Viewbox panel.

如果必须按比例拉伸所有内容(包括文本,控件和图像),请将主面板大小固定为200x400并将其包含在Viewbox面板中。

A problem may arise when the user resizes the window in a non proportional way like to 300x400. Then depending on the Viewbox.StretchDirection and Stretch properties you may have a distorted layout or empty areas. To solve this you can constraint the window size to a certain ratio.

当用户以非比例方式(例如300x400)调整窗口大小时,可能会出现问题。然后,根据Viewbox.StretchDirection和Stretch属性,您可能会出现扭曲的布局或空白区域。要解决此问题,您可以将窗口大小限制为特定比率。

#2


1  

You can take a look at the implementation of the ColorPicker control here: http://livegeometry.codeplex.com/SourceControl/changeset/view/34720#405553 especially MeasureOverride, ArrangeOverride and ComputeScaleFactor. m_Scale is the ScaleTransform that is applied to the entire control.

您可以在此处查看ColorPicker控件的实现:http://livegeometry.codeplex.com/SourceControl/changeset/view/34720#405553,尤其是MeasureOverride,ArrangeOverride和ComputeScaleFactor。 m_Scale是应用于整个控件的ScaleTransform。

You can also use SizeToContent and LayoutTransform if necessary.

如有必要,您还可以使用SizeToContent和LayoutTransform。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/11/06/33f6caca1d5a5ac7b32407840c599067.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号