我将开发一个需要向用户呈现图像组的触摸屏应用程序(不是网络应用程序)。希望呈现具有页面前进/后退功能的 3x3 图像网格。他们可以选择一些,我将只展示这些图像。
我没有看到ListView
它完全符合我的要求(尽管 WPF 足够大,我很可能错过了一些明显的东西!)。我可以在网格位置设置一个Grid
和填充图像。但我希望有更好、更自动化、更少暴力的东西。有什么想法或指示吗?
您可能希望使用ItemsControl
/ListBox
然后将UniformGrid
面板设置为 3x3 显示,ItemsPanel
以实现适当的 WPF 可绑定解决方案。
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="3" Columns="3"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<Image Source="Images\img1.jpg" Width="100"/>
<Image Source="Images\img2.jpg" Width="50"/>
<Image Source="Images\img3.jpg" Width="200"/>
<Image Source="Images\img4.jpg" Width="75"/>
<Image Source="Images\img5.jpg" Width="125"/>
<Image Source="Images\img6.jpg" Width="100"/>
<Image Source="Images\img7.jpg" Width="50"/>
<Image Source="Images\img8.jpg" Width="50"/>
<Image Source="Images\img9.jpg" Width="50"/>
</ListBox>
如果您在此处寻找动态解决方案,则需要将您的图像集合设置为 ItemsSource 绑定。但这个问题太宽泛,无法给出准确的答案。
您可以使用简单的ListBox
控件并自定义其ItemsPanel
模板并添加WrapPanel
到其中。 WrapPanel
将项目置于水平平铺布局中,您可以在其中设置其最大宽度以将 3 个项目合并到一行中,它将为 3 个项目创建更多行,直到最后一个填满。