[UWP] StackPanel as ItemsControl.ItemsPanel - 项目大小 [英] [UWP]StackPanel as ItemsControl.ItemsPanel - item sizes
问题描述
我有一个ItemsControl,我想垂直添加项目,但我需要它们缩小到相同的大小。 基本上,我想要相同的行为,就好像我为每个添加的控件都有一个RowDef为Height = *的Grid。 但是,当我使用
StackPanel作为ItemsPanel时,每个项目都是ItemsControl的大小,因此我必须滚动才能看到我的新项目。 我根本不想滚动,但我也不希望剪切我的项目 - 我需要调整大小。但是,我无法在UWP中找到任何允许我这样做的
。 我假设我错过了一些属性,因为这必须是可能的,但我只是没有看到它。
I've got an ItemsControl where I want to add items vertically, but I need them all to shrink to be of equal size. Basically, I want the same behavior as if I had a Grid with a RowDef of Height=* for each control I add. However, when I use a
StackPanel as the ItemsPanel, every item is the size of the ItemsControl such that I have to scroll to see my new items. I don't want to scroll at all, but I also don't want my items to be clipped - I need to resized. However, I cannot find anything
in UWP that would allow me to do this. I'm assuming I am missing some property, as this has to be possible, but I'm just not seeing it.
推荐答案
您好
欢迎
到开发通用Windows应用论坛 !请使用 标记 当
发布到此论坛时,谢谢!
您可以在 ItemContainerStyle中为项目设置固定高度
You can just set fixed Height for Items in ItemContainerStyle
<Page.Resources>
<Style x:Key="ListViewItemStyle1" TargetType="ListViewItem" >
<Setter Property="Height" Value="50" />
</Style>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ItemsControl x:Name="MyListView" HorizontalAlignment="Stretch"
Margin="10" VerticalAlignment="Stretch"
ItemContainerStyle="{StaticResource ListViewItemStyle1}">
<ListViewItem>
<Button Height="500" Width="300"/>
</ListViewItem>
<ListViewItem>
<Button Height="500" Width="300"/>
</ListViewItem>
<ListViewItem>
<Button Height="500" Width="300"/>
</ListViewItem>
</ItemsControl>
</Grid>
这篇关于[UWP] StackPanel as ItemsControl.ItemsPanel - 项目大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!