问题描述
有没有人有一个想法如何保持高度/宽度比1:一个用户控件的1
Does anyone have an idea how to keep the Height/Width Ratio 1:1 of a UserControl?
例如。如果高度>宽度,宽度和放大器;高度将有相同的大小,反之亦然。
E.g. if Height > Width, Width & Height will have the same size and vice versa.
推荐答案
我不知道这会工作,但如果你注册一个处理对于事件保持纵横比为1:1。
I'm not sure this will work, but if you register a handler for the SizeChanged
event and in there put in your code keep the aspect ratio 1:1.
的参数有旧的尺寸和新的大小,以便您可以检查哪些改变并相应地更新等。
The SizeChangedEventArgs
argument has the old size and the new size so you can check which has changed and update the other accordingly.
您可能需要引入一个保护变量,这样你就不会得到时,SizeChanged $ C的级联$ C>事件更新
身高的结果
或宽度
。
You might need to introduce a guard variable so that you don't get a cascade of SizeChanged
events as a result of updating the Height
or Width
.
这篇关于如何保持用户控件的宽高比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!