展开最后一个网格行以填充 wpf 应用程序中的窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19934395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expand last grid row to fill window in wpf application
提问by Sharath
I have the following Grid setup in a WPF application.
我在 WPF 应用程序中有以下网格设置。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="220" />
<RowDefinition Height="40" />
<RowDefinition Height="80" />
<RowDefinition Height="180*" />
</Grid.RowDefinitions>
<!-- some content -->
</Grid>
What I want is for the final row to take up as much height as available in its parent. But it does not seem to honor my '*' command in the final row definition.
我想要的是最后一行占据其父级中可用的尽可能多的高度。但它似乎并不尊重我在最后一行定义中的“*”命令。
Please note that I want all other row heights to be fixed..
请注意,我希望修复所有其他行高。
Is this possible? If so how? Any help or pointers are appreciated..
这可能吗?如果是这样怎么办?任何帮助或指示表示赞赏..
回答by Ehsan Hafeez
place height="*" in last row.
将 height="*" 放在最后一行。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="220" />
<RowDefinition Height="40" />
<RowDefinition Height="80" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
回答by Mike Strobel
What you have written should be fine (though as @Bolu commented, the 180*could be replaced with *in this case). If the content in the last row is not expanding to fill the available size, I would suspect one of the following:
你写的应该没问题(尽管正如@Bolu 评论的180*那样,*在这种情况下可以替换为)。如果最后一行中的内容没有扩展以填充可用大小,我会怀疑以下情况之一:
The
Gridmay be nested somewhere below a layout panel that does not arrange its children to fill all available vertical space. For example, is one of theGridpanel's ancestors aStackPanel? A good way to test whether this is the culprit is to comment out the entireGridand replace it with aBorderwith an easily distinguishable background (e.g.,Magenta) and see if it occupies the entire area you expect theGridto fill.There may not actually be any content in the last row. Did you set the correct
Grid.Rowvalue correctly?You may be overriding the layout behavior of the last row's content. Are you setting the content's
VerticalAlignmentto anything other thanStretch?
该
Grid可低于布局面板,不安排其子,以填补所有可用的垂直空间嵌套的地方。例如,Grid面板的祖先之一是StackPanel? 测试这是否是罪魁祸首的一个好方法是注释掉整个Grid并用Border易于区分的背景(例如,Magenta)替换它,然后查看它是否占据了您希望Grid填充的整个区域。最后一行实际上可能没有任何内容。您是否
Grid.Row正确设置了正确的值?您可能会覆盖最后一行内容的布局行为。您是否将内容设置为?
VerticalAlignment以外的任何内容Stretch?
回答by Federico Berasategui
Remove the Heightproperty from the last Row:
Height从最后一行中删除属性:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="220" />
<RowDefinition Height="40" />
<RowDefinition Height="80" />
<RowDefinition/>
</Grid.RowDefinitions>
<!-- some content -->
</Grid>

