Resizing a WPF ResizeMode Window

I am currently creating a wpf application and want to disable window resizing during certain operations. I used this.ResizeMode = System.Windows.ResizeMode.CanMinimize; which does exactly what I want, but makes the window bigger than before.

I do not know if this is possible, but is there a way to avoid enlarging the window?

EDIT:

Here's a very simple wpf application demonstrating 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; } } } 
+6
source share
1 answer

In fact, I really donโ€™t understand what โ€œmakes the window biggerโ€ means, but as an alternative, you can set

 MaxWidth = ActualWidth; MinWidth = ActualWidth; MaxHeight = ActualHeight; MinHeight = ActualHeight; 

instead

 this.ResizeMode = System.Windows.ResizeMode.CanResize; 

If you want to re-enable resizing, set these properties to double.NaN .

.

0
source

Source: https://habr.com/ru/post/957591/


All Articles