【发布时间】:2023-03-05 11:57:01
【问题描述】:
我有一个ListView,我想在其中水平显示内容。这很好用,但现在我需要让它们像 Windows 资源管理器类型一样显示。
例如:
A B C
D E F
G H I
或
A B
C D
E F
G H
I
可以在ListView 中使用吗?
【问题讨论】:
标签: wpf templates xaml listview
我有一个ListView,我想在其中水平显示内容。这很好用,但现在我需要让它们像 Windows 资源管理器类型一样显示。
例如:
A B C
D E F
G H I
或
A B
C D
E F
G H
I
可以在ListView 中使用吗?
【问题讨论】:
标签: wpf templates xaml listview
如果您希望您的商品都具有相同的尺寸,我会选择UniformGrid。它是那些被忽视的控件之一,在这种情况下可能非常有用。
这就是我制作快速而肮脏的工具栏的方式:
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding}"
ToolTip="{Binding Tooltip}">
<StackPanel Orientation="Vertical">
<Image Height="16"
Width="16"
RenderOptions.BitmapScalingMode="NearestNeighbor"
Source="{Binding Image}"
HorizontalAlignment="Center" />
</StackPanel>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
【讨论】:
听起来您正在寻找 WrapPanel。我认为它不适用于 ListView,但如果您希望通用项目容器使用 WrapPanel 作为其布局,您可以使用 ItemsControl 执行此操作并用您想要的任何元素填充它。类似于以下内容:
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Items>
<TextBlock Margin="20" Padding="20" Text="Blah" Background="#999" />
<TextBlock Margin="20" Padding="20" Text="Blah" Background="#999" />
<TextBlock Margin="20" Padding="20" Text="Blah" Background="#999" />
<TextBlock Margin="20" Padding="20" Text="Blah" Background="#999" />
<TextBlock Margin="20" Padding="20" Text="Blah" Background="#999" />
<TextBlock Margin="20" Padding="20" Text="Blah" Background="#999" />
</ItemsControl.Items>
</ItemsControl>
【讨论】: