Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Window - Only allow horizontal resize

Tags:

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

like image 931
David Ward Avatar asked Jun 23 '10 06:06

David Ward


2 Answers

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:

<Window x:Class="MyWindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         SizeToContent="WidthAndHeight"         ResizeMode="CanResize"         Loaded="window_Loaded"> 

In code-behind:

private void window_Loaded(object sender, RoutedEventArgs e) {     this.MinWidth = this.ActualWidth;     this.MinHeight = this.ActualHeight;     this.MaxHeight = this.ActualHeight; } 
like image 150
User3810621 Avatar answered Sep 24 '22 20:09

User3810621


If you set the MinHeight and MaxHeight attributes of the window to the desired height the window will have a fixed height

like image 44
user375075 Avatar answered Sep 21 '22 20:09

user375075