Forcing width==height on resize

I want my main window to be resizeable, and I'm using a viewbox such that my content scales accordingly when the window is resized...however I want to fix a relationship between the width and height of the window. (For example, I want to force the width and height to be equal). It's not clear to me how I can do this in XAML. I also couldn't find a resize or preview resize event that I can capture and force the relationship programmatically.

Any suggestions



Answer this question

Forcing width==height on resize

  • George Birbilis

    As a compromise, you could set the Stretch property on the Viewbox to "Uniform". This would ensure that the content of the Viewbox wouldn't be distorted. It wouldn't, however, prevent the Window itself from being arbitrarily sized.

  • shailesh_ch

    I am not sure how you would do this all in xaml.  But, in code you can listen for the SizedChange event on the window.  Once that gets fired you can set your Height == Width.

  • Forcing width==height on resize