gpt4 book ai didi

c# - 使用 ListBox 和 StackPanel 的所有可用空间作为 ItemsPanelTemplate

转载 作者:太空宇宙 更新时间:2023-11-03 12:57:39 25 4
gpt4 key购买 nike

我使用 ListBox 在我的 View 中显示 ObservableCollection 的内容。在我的简化示例中,我只是为每个项目使用一个图像,如下所示:

<Window>
<Window.Resources>
<DataTemplate DataType="{x:Type viewModel:HealthCriterionViewModel}">
<Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Source="Optionsh.png" Stretch="Fill" />
</DataTemplate>
</Window.Resources>

<ListBox ItemsSource="{Binding HealthCriteria}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Window>

HealthCriteriaHealthCriterionViewModel 类型的集合。

我得到的是这样的:

enter image description here

我想要的是这个(拉伸(stretch)图像以在垂直和水平方向上使用所有可用空间):

enter image description here

我怎样才能做到这一点?

最佳答案

我建议你不能用ItemsControl来实现。因为内容展示器大小不固定,所以它是可滚动区域。所以每个元素的大小应该是固定的。它可以直接在具有“重量”或“高度”(取决于方向)属性的 ItemsPanel 中进行限制,或者受内容大小限制。

关于c# - 使用 ListBox 和 StackPanel 的所有可用空间作为 ItemsPanelTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33365754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com