WPF Window - Only allow horizontal resize

后端 未结 8 1221
一生所求
一生所求 2021-01-03 23:02

I want to only allow my WPF window to be resized horizontally. How best can I achieve this?

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 23:59

    If you want to use the MinHeight and MaxHeight approach but still allow the window to automatically size itself to fit the size of its content:

    
    

    In code-behind:

    private void window_Loaded(object sender, RoutedEventArgs e)
    {
        this.MinWidth = this.ActualWidth;
        this.MinHeight = this.ActualHeight;
        this.MaxHeight = this.ActualHeight;
    }
    

提交回复
热议问题