Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Grid horizontalalignment doesn't work. Sizes don't changes

I have a Stack and I have a Grid inside of Stack.

I need to increase Stack and Grid sizes when I resize the window. I set Stack and Grid HorizontalAlignment to 'Stretch'

Stack works fine but grid sizes don't raises when I resize the window

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 advise

like image 406
developergg Avatar asked Oct 20 '22 21:10

developergg


1 Answers

Even if you removed with Width from the Grid, it won't work because the StackPanel's orientation is set to Horizontal. When it is set like this, the StackPanel gives it's children exactly the amount of width they say they need during the measure layout pass See Layout here.

To fix this, you'll need to change the orientation to Vertical, or use a different container such as a DockPanel

like image 53
ptsoccer Avatar answered Oct 27 '22 00:10

ptsoccer