views:

323

answers:

2

I have a user resizable WPF Window that I want to constrain the resizing so the aspect ratio of the window stays constant.

Ideally I would like to constrain mouse location when the window is being resized by dragging a corner to positions that maintain the proper aspect ration. If an edge is resized with the mouse, the other dimension should change at the same time.

Is there a simple way to do this or a good on-line example that anyone knows of?

If no better solutions come up, I'll post what I've done after I've refined it a bit.

A: 

Hi, Did you find any solution? Thanks

arthurh
I have a solution, but it isn't quick or easy. I trap the window resize event. I use a behavior to trap WndProc and check for resize, and then change the rectangle it is getting resized to. Maybe I'll write it up for Code Project. If it is something you really need I'll at least find the references that I used to figure it out for you.
rathkopf
A: 

Does that do the trick:

protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) {

    if (sizeInfo.WidthChanged) this.Width = sizeInfo.NewSize.Height * aspect;
    else this.Height = sizeInfo.NewSize.Width / aspect;
}

Found it here.

742