我是UWP开发的新手。现在我只实现一个水平listView。这是我的代码:
<Grid Background="{StaticResource DefaultBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Height="100" Grid.Row="0"/>
<controls:TestListView Grid.Row="1" x:Name="MyListView" IsItemClickEnabled="False" ItemsSource="{x:Bind Folders}" Margin="10,0,10,0"
ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Auto">
<ListView.ItemTemplate>
<DataTemplate x:DataType="model:TestClass">
<controls:TestControl/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Width" Value="270"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Disabled"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</controls:TestListView>
</Grid>
我希望MyListView
垂直占据所有空间。请注意,TestControl
(UserControl)是另一个ListView。它可能包含大量物品。最终结果是MyListView
的高度等于所有TestControl
中的最大高度。我希望TestControl
应该显示一个滚动条,而不是仅显示一个长列表,但它没有。
那么如何使所有TestControl
的高度适应于高度
UWP申请?
答案 0 :(得分:0)
最后,我得到了我想要的东西。只需进行以下更改,一切都很好。
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollMode="Auto" ScrollViewer.VerticalScrollMode="Disabled"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>