[英]How can I make a ListBoxItem stretch Vertically
I would like to make a ListBox
function like a Grid
. 我
ListBox
Grid
一样创建一个ListBox
函数。 Each time a new item is added it should look like aa new GridRow
was added (with a height of star). 每次添加新项目时,它应该看起来像添加了一个新的
GridRow
(高度为星号)。 So if there are two items they will each take up half of the available space. 因此,如果有两个项目,它们将占用可用空间的一半。 At some point the
Grid
row will be smaller than the items MinHeight
at which point the Grid
will expand and a containing ScrollViewer can kick in. 在某些时候,
Grid
行将小于MinHeight
项,此时Grid
将展开并且包含ScrollViewer可以启动。
You will see this behavior with a grid inside a ScrollViewer
. 您将在
ScrollViewer
看到一个网格的行为。 However, I need to get this working with a ListBox
so I can just set the ItemsSource
, create a DataTemplate
and move on. 但是,我需要使用
ListBox
这样我就可以设置ItemsSource
,创建一个DataTemplate
并继续前进。
The problem with the default ListBox
ItemsPanel
is that it will not let my first item expand to fill all the available space. 默认的
ListBox
ItemsPanel
的问题是它不会让我的第一个项目展开以填充所有可用空间。
UPDATE: Here's the code to get it working: 更新:这是让它工作的代码:
<ListBox VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Width="Auto" Height="Auto">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1"></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
这个SO帖子有一些非常好的信息似乎与你的帖子WPF相关- 为什么列表框项目不填充uniformgrid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.