Search code examples
wpfxamlexpression-blend

Fitting the content to the entire window space on maximization - WPF


When I run the project and maximize the window, the design layout covers on the top left portion of the window. How can I fill the entire window with the layout on maximization?

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="40"/>
        <RowDefinition Height="50"/>
        <RowDefinition Height="320"/>
        <RowDefinition Height="70" />
        </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="290" />

    </Grid.ColumnDefinitions>

    <Menu Background="#FFDED9D9" Grid.Row="0" Grid.ColumnSpan="8"  />

    <Menu Background="#FFDED9D9" Grid.Row="1" Grid.ColumnSpan="8" />

    <DataGrid Grid.Row="2" Grid.ColumnSpan="8"  />

    <StatusBar Grid.Row="3" Background="#FFDED9D9"  Grid.ColumnSpan="8" Margin="0,0,0,30" />
        </Grid>


Solution

  • Instead of setting Height and Width of all Rows and Columns of LayoutGrid, set Height and Width of any one Column and Row as *

    Here, for example your DataGrid row can have Height as * <RowDefinition Height="*"/>. Similarly last ColumnDefinition can be <ColumnDefinition Width="*" />