Mainwindow changes size by itself when running the application

Asked

Viewed 48 times

0

Greetings!

I created a small XAML window in a WPF project where in Design view is perfect, but when I run the application in Debug mode the window changes in size on its own. What to do so that the window size does not change?

Below follow the screen prints to facilitate understanding.

Design time

Design View

Debug time

Runtime View

XAML

    <Window x: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.

Hug to all!

1 answer

0

I managed to solve my problem with the help of some comrades from Stackoverflow in English.

Here’s what I learned!

  1. I withdrew Width and Height of the element Window and added SizeToContent="WidthAndHeight";
  2. In the element Grid i defined Width="500" and Height="350".

Okay, it worked well for me, and I hope it fits someone else.

Simple as that!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.