I want to only allow my WPF window to be resized horizontally. How best can I achieve this?
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; }
If you set the MinHeight
and MaxHeight
attributes of the window to the desired height the window will have a fixed height
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With