简体   繁体   English

WPF Grid horizo​​ntalalignment不起作用。 尺寸不会改变

[英]WPF Grid horizontalalignment doesn't work. Sizes don't changes

I have a Stack and I have a Grid inside of Stack. 我有一个Stack,我在Stack里面有一个Grid。

I need to increase Stack and Grid sizes when I resize the window. 我调整窗口大小时需要增加堆栈和网格大小。 I set Stack and Grid HorizontalAlignment to 'Stretch' 我将Stack和Grid Horizo​​ntalAlignment设置为'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 请指教

Even if you removed with Width from the Grid, it won't work because the StackPanel's orientation is set to Horizontal. 即使您从网格中删除了Width,它也无法工作,因为StackPanel的方向设置为Horizo​​ntal。 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 . 当它设置为这样时,StackPanel为它的子项准确地指出它们在度量布局过程中所需的宽度量请参见此处的布局

To fix this, you'll need to change the orientation to Vertical, or use a different container such as a DockPanel 要解决此问题,您需要将方向更改为“垂直”,或使用其他容器(如DockPanel)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM