C# WPF 图片库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1183109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Image Gallery
提问by Russ
I'm going to be driving a touch-screen application (not a web app) that needs to present groups of images to users. The desire is to present a 3x3 grid of images with a page forward/backward capability. They can select a few and I'll present just those images.
我将要开发一个需要向用户呈现图像组的触摸屏应用程序(不是网络应用程序)。希望呈现具有页面向前/向后功能的 3x3 图像网格。他们可以选择一些,我将只展示这些图像。
I don't see that ListView
does quite what I want (although WPF is big enough that I might well have missed something obvious!). I could set up a Grid
and stuff images in the grid positions. But I was hoping for something nicer, more automated, less brute-force. Any thoughts or pointers?
我没有看到这ListView
完全符合我的要求(尽管 WPF 足够大,我很可能错过了一些明显的东西!)。我可以Grid
在网格位置设置一个和填充图像。但我希望有更好、更自动化、更少暴力的东西。任何想法或指示?
采纳答案by Jobi Joy
You might want to use an ItemsControl
/ListBox
and then set a UniformGrid
panel for a 3x3 display as its ItemsPanel
to achieve a proper WPF bindable solution.
您可能希望使用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>
You need to set your collection of Images as ItemsSource binding if you are looking for a dynamic solution here. But the question is too broad to give an exact answer.
如果您正在此处寻找动态解决方案,则需要将您的图像集合设置为 ItemsSource 绑定。但是这个问题太宽泛了,无法给出准确的答案。
回答by Akash Kava
You can use simple ListBox
control and customize its ItemsPanel
template and add WrapPanel
in it. WrapPanel
puts items in a Horizontal Tiling layout, where you can set its max width to incorporate 3 items in one row and it will create more rows for 3 items till last one fills.
您可以使用简单的ListBox
控件并自定义其ItemsPanel
模板并添加WrapPanel
到其中。 WrapPanel
将项目置于水平平铺布局中,您可以在其中设置其最大宽度以将 3 个项目合并为一行,它将为 3 个项目创建更多行,直到最后一个填充为止。
回答by EdgarT
I know that this is a pretty old question, but I'm answering because this page is in the first page on Google and this link could be useful for someone.
我知道这是一个很老的问题,但我回答是因为这个页面在谷歌的第一页,这个链接可能对某人有用。
Screenshot:
截屏: