WPF网格的Horizo​​ntalAlignment不起作用。大小不改变 [英] WPF Grid horizontalalignment doesn't work. Sizes don't changes

查看:227
本文介绍了WPF网格的Horizo​​ntalAlignment不起作用。大小不改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个堆栈,我有一个网格栈内。

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

我需要增加堆栈和网格尺寸,当我调整窗口的大小。 我设置堆栈和网格Horizo​​ntalAlignment以拉伸

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

这是我的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>

请指教

推荐答案

即使你与宽度从网格中删除,也不会工作,因为StackPanel中的方向设置为横向。当设置这样的,StackPanel的给它的孩子正是宽度他们说量,他们测量的布局通过的请参见布局这里

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.

要解决这个问题,你需要的方向改为垂直,或使用不同的容器,​​如DockPanel中

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

这篇关于WPF网格的Horizo​​ntalAlignment不起作用。大小不改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆