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

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


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.


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


2 个解决方案



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.


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.




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.




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