Horizontal alignment of WPF grid does not work. Dimensions do not change

I have a Stack and I have a grid inside a Stack.

I need to increase the size of the Stack and Grid when the window is resized. I set Stack and Grid HorizontalAlignment to "Stretch"

The stack works fine, but the grid sizes do not occur when the window is resized

This is my code.

<StackPanel Background="Blue" Orientation="Horizontal" HorizontalAlignment="Stretch" Grid.Column="1" Margin="13,0,0,0" >
   <Grid HorizontalAlignment="Stretch" Background="Beige" Width="515">

        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="240" />
            <RowDefinition Height="100" />
        </Grid.RowDefinitions>

        <Image x:Name="imageMap" Source="Resources/images.jpg" HorizontalAlignment="Stretch" Grid.Row="0" Stretch="Fill" Margin="0,0,0,0" />

   </Grid>
</StackPanel>

      

Please inform

+3


source to share


1 answer


Even if you removed using Width from the Grid, it won't work because the orientation of the StackPanel is set to "Horizontal". When set like this, the StackPanel gives it exactly the amount of width they see fit during the layout of the layout. See here for the layout .



To fix this you will need to change the orientation to Vertical or use another container like DockPanel

+3


source







All Articles