developergg
developergg

Reputation: 857

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

Upvotes: 5

Views: 3772

Answers (1)

ptsoccer
ptsoccer

Reputation: 158

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

Upvotes: 4

Related Questions