views:

322

answers:

1

Hello,

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.

Thanks for any help.

Cheers

+1  A: 

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 the Height or Width.

ChrisF
I think control will be blinking when resizing.
SMART_n
It will not blink because WPF uses retained mode and rendering is done at a lower priority, so rendering will see the final result of all the `SizeChanged` events. Exception: If your Window is `SizeToContent` and its size is affected, `SetWindowPos()` is called immediately during the calculations so you probably will see something.
Ray Burns