Resolved How do I adjust the window size to the monitor resolution?

Wkesther

Member
Joined
Aug 6, 2022
Messages
24
Programming Experience
Beginner
Hello, I am currently creating a recipe book - app. I have set the size of the MainWindow to 2560 x 1440. Now I would like to change the size of the MainWindow to a dynamic resolution in order to run my application on any scrrensize without cutting it off. So it automatically fills out the whole screen, no mather how big the screen is.

MainWindow:
<Window x:Class="recipeBook.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:recipeBook"
        mc:Ignorable="d"
        Title="MainWindow" Height="1440" Width="2560">
 
That's because of your bad design. The window will be the same size if it's maximised or you just make the window bigger. If you create the window layout properly then it will grown and shrink correctly.
 
What do I have to change, in order to make this work properly. I am really sorry if it is defined horrably...I am still pretty new to WPF.
Thats how the window is defined:

MainWindow:
<Window x:Class="recipeBook.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:recipeBook"
        mc:Ignorable="d"
        Title="MainWindow" Height="1400" Width="2560">
    <Window.Background>
        <ImageBrush ImageSource="D:\MyApplications\recipeBook\recipeBook\Images\wood-2142241.jpg"/>
    </Window.Background>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="1229"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="52*"/>
            <RowDefinition Height="51*"/>
            <RowDefinition Height="609*"/>
        </Grid.RowDefinitions>
        <TextBlock Text="Rezeptbuch"
                   Style="{StaticResource headline}"
                   Grid.Column="1"
                   TextAlignment="Center" Margin="10,10,10,10"/>
        <Label Content="Kategorien"
               FontSize="60"
               FontWeight="Bold"
               HorizontalAlignment="Center"
               Width="323" Margin="0,104,0,0" Grid.RowSpan="2"/>
        <StackPanel Grid.Row="2">
            <CheckBox x:Name="meatCheckBox"
                      FlowDirection="RightToLeft"
                      Width="16" Height="15"
                      HorizontalAlignment="Right"
                      Margin="0 10 10 0">
                <CheckBox.LayoutTransform>
                    <ScaleTransform ScaleX="5" ScaleY="5"/>
                </CheckBox.LayoutTransform>
            </CheckBox>
            <CheckBox x:Name="fishCheckBox"
                      FlowDirection="RightToLeft"
                      Width="16" Height="16"
                      HorizontalAlignment="Right"
                      Margin="0 10 10 0">
                <CheckBox.LayoutTransform>
                    <ScaleTransform ScaleX="5" ScaleY="5"/>
                </CheckBox.LayoutTransform>
            </CheckBox>
            <CheckBox x:Name="vegetarianCheckBox"
                      FlowDirection="RightToLeft"
                      Width="16" Height="15"
                      HorizontalAlignment="Right"
                      Margin="0 10 10 0">
                <CheckBox.LayoutTransform>
                    <ScaleTransform ScaleX="5" ScaleY="5"/>
                </CheckBox.LayoutTransform>
            </CheckBox>
            <CheckBox x:Name="veganCheckBox"
                      FlowDirection="RightToLeft"
                      Width="16" Height="15"
                      HorizontalAlignment="Right"
                      Margin="0 10 10 0">
                <CheckBox.LayoutTransform>
                    <ScaleTransform ScaleX="5" ScaleY="5"/>
                </CheckBox.LayoutTransform>
            </CheckBox>
            <CheckBox x:Name="proteinCheckBox"
                      FlowDirection="RightToLeft"
                      Width="16" Height="15"
                      HorizontalAlignment="Right"
                      Margin="0 10 10 0">
                <CheckBox.LayoutTransform>
                    <ScaleTransform ScaleX="5" ScaleY="5"/>
                </CheckBox.LayoutTransform>
            </CheckBox>
            <CheckBox x:Name="dessertCheckBox"   
                      FlowDirection="RightToLeft"
                      Width="16" Height="15"
                      HorizontalAlignment="Right"
                      Margin="0 10 10 0">
                <CheckBox.LayoutTransform>
                    <ScaleTransform ScaleX="5" ScaleY="5"/>
                </CheckBox.LayoutTransform>
            </CheckBox>
        </StackPanel>
        <StackPanel Grid.Row="2" Margin="10 0 0 0">
            <TextBlock Text="Fleisch"
                   Grid.Row="2"
                   FontSize="55"
                   Margin="0 10 0 0" Width="auto"
                   HorizontalAlignment="Left"/>
            <TextBlock
                   Grid.Row="2"
                   FontSize="55"
                   Margin="0 10 0 0"
                   Text="Fisch" Width="auto"
                   HorizontalAlignment="Left"/>
            <TextBlock Text="Vegetarisch"
                   Grid.Row="2"
                   FontSize="55"
                   Margin="0 10 0 0" Width="auto"
                   HorizontalAlignment="Left"/>
            <TextBlock Text="Vegan"
                   Grid.Row="2"
                   FontSize="55"
                   Margin="0 10 0 0" Width="auto"
                   HorizontalAlignment="Left"/>
            <TextBlock Text="Proteinreich"
                   Grid.Row="2"
                   FontSize="55"
                   Margin="0 10 10 0" Width="auto"
                   HorizontalAlignment="Left"/>
            <TextBlock Text="Desserts"
                   Grid.Row="2"
                   FontSize="55"
                   Margin="0 10 10 0" Width="auto"
                   HorizontalAlignment="Left"/>
        </StackPanel>
        <Button x:Name="randomRecipe"
                Grid.Column="1"
                Grid.Row="1"
                Content="zufälliges Rezept"
                FontSize="50"
                Margin="10,10,10,10"/>
        <StackPanel Grid.Row="2" Grid.Column="1" Margin="10">
            <TextBox x:Name="searchRecipeTbx"
                     Margin="10"
                     Height="57"
                     FontSize="30"
                     BorderBrush="DarkSlateGray" BorderThickness="5"/>
            <ListView x:Name="recipeList">
            </ListView>
        </StackPanel>
        <StackPanel Grid.Column="2" Grid.Row="3" Margin="10">
            <Label Content="Rezeptname:" FontSize="35" FontWeight="Bold"/>
            <TextBox x:Name="recipeNameTbk"
                     FontSize="30"
                     Style="{StaticResource addRecipeBoxes}" Height="auto"/>
            <Label Content="Nährwerte" FontSize="35" FontWeight="Bold"/>
            <TextBox x:Name="nutritionalValuesTbk"
                     FontSize="30"
                     Style="{StaticResource addRecipeBoxes}" Height="auto"/>
            <Label Content="Zutaten" FontSize="35" FontWeight="Bold"/>
            <TextBox x:Name="ingridientsTbk"
                     FontSize="30"
                     Style="{StaticResource addRecipeBoxes}" Height="auto"/>
            <Label Content="Zubereitung" FontSize="35" FontWeight="Bold"/>
            <TextBox x:Name="preparationTbk"
                     FontSize="30"
                     Style="{StaticResource addRecipeBoxes}" Height="auto"/>
            <Button x:Name="addRecipe"
                    Click="addRecipe_Click"
                    Margin="10 5 10 5" Height="100"
                    Background="LightGreen"
                    Content="Rezept hinzufügen"
                    BorderBrush="DarkSlateGray"
                    BorderThickness="5"
                    FontSize="50"
                    FontWeight="Bold"/>
        </StackPanel>
        <Label Content="Rezept hinzufügen"
               Grid.Row="1"
               Grid.Column="2"
               FontSize="60"
               FontWeight="Bold"
               HorizontalAlignment="Center"/>
    </Grid>
</Window>
 
You should start with a much simpler window and learn how to make controls resize in various ways as their container does. Always start simple, learn the principles involved and then apply those principles to more and more complex scenarios.
 
Hello, I am currently creating a recipe book - app. I have set the size of the MainWindow to 2560 x 1440. Now I would like to change the size of the MainWindow to a dynamic resolution in order to run my application on any scrrensize without cutting it off. So it automatically fills out the whole screen, no mather how big the screen is.

MainWindow:
<Window x:Class="recipeBook.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:recipeBook"
        mc:Ignorable="d"
        Title="MainWindow" Height="1440" Width="2560">
Add WindowState="Maximized" in your Window XAML.
 

Latest posts

Back
Top Bottom