Search code examples
.netwpfmvvmresizewindow

Allow resizing while keeping scale proportions on Window


I want to have a window that the User can resize, and I want this window to keep the scale proportions (MVVM way if it is possible !).

I have two different approaches:

  • Handling the SizeChangedEvent and adjust Width or Height. Worked but the Window had really weird animations while resizing.
  • Handling the MouseUp event, to adjust Width or Height when the User releases the button (when resizing). Unfortunately, the MouseUp event doesn't trigger when you release the LeftButton after resizing. I couldn't use MouseBinding because MouseGesture doesn't have a "MouseUp" parameter, only a LeftClick!

Can you help me, giving me advice, code, links or anything useful?


Solution

  • The first approch you are taking is correct, another way is to use win32 interop as explained in following posts -

    http://blog.mikeobrien.net/2009/09/maintaining-aspect-ratio-when-resizing.html

    http://social.msdn.microsoft.com/forums/en-US/wpf/thread/b0df3d1f-e211-4f54-a079-09af0096410e

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/77b566aa-be88-47a4-8c29-b1e44946348e/

    Other similar SO threads -

    How Can I Only Allow Uniform Resizing in a WPF Window?

    Resize a WPF window, but maintain proportions?

    but it will be tough to get rid of flickering effect altogether.