Resize a WPF window, but maintain proportions?

后端 未结 5 714
庸人自扰
庸人自扰 2020-11-30 08:13

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

5条回答
  •  无人及你
    2020-11-30 08:41

    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.

提交回复
热议问题