【发布时间】:2020-07-07 02:43:10
【问题描述】:
我正在使用 ListView 开发 UWP,并且正在努力实现一些基本功能。
我有一个水平 ListView,其中包含需要可变宽度的项目。并且宽度需要是动态的,因为我想根据它的内容展开或缩回它。准确地说,每个项目在 StackPanel 内都有多个矩形,我希望能够添加更多矩形,并且我希望项目的宽度呈指数增长。
现在,这些项目似乎具有相同且锁定的大小。如果我增加一个项目的内容,其他项目的宽度也会增加。
我是 UWP 新手,不知道如何实现这样的功能。
<ListView Name="Grid"
Grid.Row="0"
HorizontalAlignment="Stretch"
BorderThickness="0"
ItemsSource="{x:Bind Items, Mode=TwoWay}"
ItemTemplateSelector="{StaticResource TemplateSelector}"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.VerticalScrollMode="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
IsItemClickEnabled="True"
CanDragItems = "False"
CanDrag = "False"
CanReorderItems = "False"
AllowDrop = "False"
ItemClick="Grid_ItemClick"
SelectionChanged="Grid_SelectionChanged"
SelectionMode="Single">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Padding" Value="0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
【问题讨论】:
-
到目前为止您尝试过什么?您的项目模板是什么样的?你是如何添加额外的部分的?