'WPF ResizeMode Changes Window Size
I am currently making a wpf application and want to disable window resizing during certain operations. I have been using this.ResizeMode = System.Windows.ResizeMode.CanMinimize;, which does exactly what I want, but it makes the window larger than before.
I don't know if it's possible, but is there a way to avoid the enlarging of the window?
EDIT:
Here's a very simple wpf application that demonstrates this problem.
xaml:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button Content="Trigger CanMinimize" Height="23" HorizontalAlignment="Left" Margin="62,248,0,0" Name="canMin" VerticalAlignment="Top" Width="120" Click="canMin_Click" />
<Button Content="Trigger CanResize" Height="23" HorizontalAlignment="Left" Margin="327,248,0,0" Name="canRes" VerticalAlignment="Top" Width="108" Click="canRes_Click" />
</Grid>
</Window>
cs file:
using System.Windows;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void canMin_Click(object sender, RoutedEventArgs e)
{
this.ResizeMode = System.Windows.ResizeMode.CanMinimize;
}
private void canRes_Click(object sender, RoutedEventArgs e)
{
this.ResizeMode = System.Windows.ResizeMode.CanResize;
}
}
}
Solution 1:[1]
Actualy I don't really understand what "makes window larger" means, but alternatively you can set
MaxWidth = ActualWidth;
MinWidth = ActualWidth;
MaxHeight = ActualHeight;
MinHeight = ActualHeight;
instead of
this.ResizeMode = System.Windows.ResizeMode.CanResize;
In case you want to re-enable resize set those properties to double.NaN.
.
Solution 2:[2]
To disallow resizing simply do the following:
ResizeMode = ResizeMode.NoResize;
It will also remove the minimize and maximize buttons.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Andras Sebo |
| Solution 2 | J W |
