当一个包含列表时,如何将两个WPF网格控件设置为相同的高度? [英] How do I get two WPF grid controls to be same height when one contains a list?

查看:106
本文介绍了当一个包含列表时,如何将两个WPF网格控件设置为相同的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个WP Grid控件彼此相邻。一个人有一组固定的字段。另一个绑定到列表。我希望两个网格控件的高度相同。



我现在的代码偶然执行此操作,但它使网格控件与网格一样长包含项目列表。我想要相反的。我希望列表中的Grid与其他Grid的大小相同,并且WPF会自动将滚动条放在列表中以查看列表底部的项目。



希望这是有道理的。



亲切的愿望~Patrick



我尝试过:



我尝试过使用 Grid.IsSharedSizeScope =True在两个网格控件的容器上,然后在每个网格中,在每个网格中设置< RowDefinition SharedSizeGroup =xxxx/>



这样可以使两个网格控件保持相同的大小,但不幸的是我只能做以前的工作 - 两个网格控件都会增长以容纳列表中的所有项目。

I have two WP Grid controls next to each other. One has a fixed set of fields. The other is bound to a list. I want the two Grid controls to be the same height.

The code I have now does this 'by accident' but it makes both Grid controls as long as the Grid containing the list of items. I want the opposite. I want the Grid with the list to be locked at the same size as the other Grid and for WPF to automatically put scrollbars on the list to view items which go off the bottom of the list.

Hope this makes sense.

Kind wishes ~ Patrick

What I have tried:

I have tried using the Grid.IsSharedSizeScope="True" on the container for both Grid controls and then in each Grid, setting <RowDefinition SharedSizeGroup="xxxx"/> in each Grid.

This keeps both Grid controls the same size but unfortunately simply does what I had before - both Grid controls grow to accommodate all the items in the list.

推荐答案

网格大小受其容器大小的限制,因此您的问题意味着网格的可视树中至少有一个父级允许无限增长。例如,由于如果Grid是StackPanel的子节点,StackPanel具有无限增长,那么Grid也有无限增长。您可以更改可视树以修复有问题的元素,也可以手动设置/操作网格/容器的高度。
Grid size is bounded by the size of their container, so your problem means there's at least one parent in the visual tree of the Grid that allows unbounded growth. For example, since a StackPanel has unbounded growth if a Grid is the child of a StackPanel there is unbounded growth of the Grid as well. You can either change the visual tree to fix the offending element, or you will have to set/manipulate the height of the Grid/containers manually.


这篇关于当一个包含列表时,如何将两个WPF网格控件设置为相同的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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