MainWindow resizes by itself when I run the application

0

Greetings!

I created a small window in XAML in a WPF project where Design view is perfect, but when I run the application in Debug mode the window changes size alone. What do I do to make the window size not change?

Below are the screen prints for ease of understanding.

Design time

Debugtime

XAMLCode

<Windowx:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="500" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
    <Grid Margin="0">
        <Button Content="Button" HorizontalAlignment="Left" Margin="10,291,0,0" VerticalAlignment="Top" Width="75"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="409,10,0,0" VerticalAlignment="Top" Width="75"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="409,291,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
</Window>

Thank you in advance.

Hugs to all!

    
asked by anonymous 07.04.2017 / 23:23

1 answer

0

I was able to resolve my issue with the help of some comrades from StackOverflow in English.

Here's what I've learned!

  • I removed Width and Height from element Window and added SizeToContent="WidthAndHeight" ;
  • In element Grid I set Width="500" and Height="350" .
  • Okay, it worked out well for me and I hope it will work for someone else.

    Simple like this!

        
    08.04.2017 / 09:07