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.
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.
Try using a ViewBox and setting its Stretch property to Uniform
maybe this helps... cheers
i used this code for keeping aspect ratio
inside usercontrol globally define org_width, org_height, org_ratio :
use this code inside usercontrol in SizeChanged event:
and finally your user control code should looks like this:
good luck
Another alternative:
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.You might need to introduce a guard variable so that you don't get a cascade of
SizeChanged
events as a result of updating theHeight
orWidth
.