如何定义 WPF ListView 的每个项目,该视图看起来类似于 Windows 7 中的超大图标视图?
基本上我正在尝试做类似 this http://www .crunchgear.com/wp-content/uploads/2010/07/popbox.jpg。
仅以固定尺寸显示图像,图像下方没有文字。图像之间的水平和垂直距离也应该是固定的。
另外,如果有人可以添加鼠标悬停发光效果来模拟相同的效果,那就太酷了。
我现在对 xaml 更熟悉了,但我对为 ListView
控件定义每个项目感到困惑。我之前只使用过 WPF ListView
和 GridViewColumns
,所以这是新的。
另外,我尝试绑定具有图像的 ListView
的对象是这样的:
class Film
{
Image Image {get;set;}
}
但是如果我应该将它们存储在 Image
之外的不同类型中,那也很酷。
Basically I am trying to do something like this http://www.crunchgear.com/wp-content/uploads/2010/07/popbox.jpg.
Just showing images in a fixed dimension with no text below the images. It also should have a fixed distance between the images horizontally and vertically.
Also if someone could add a mouseover glow effect to simulate the same thing, that would be cool.
I am more familiar with xaml now but I just got confused about defining each item for a ListView
control. I only used WPF ListView
with GridViewColumns
before so this is new.
Also the object I am trying to bind the ListView
that has the images is something like this:
class Film
{
Image Image {get;set;}
}
But if I should store them in a different type other than Image
, that's cool too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个快速而肮脏的示例,它提供了与您想要的效果类似的效果:
XAML
Film class
Code-behind
(您也可以使用 ViewModel类作为 DataContext,为了简单起见,我在这里使用了代码隐藏)
光环现在很丑陋,但是嘿,我不是设计师;)
Here's a quick and dirty example that gives an effect similar to what you want:
XAML
Film class
Code-behind
(You could also use a ViewModel class as the DataContext, I used code-behind here for the sake of simplicity)
The halo is quite ugly right now, but hey, I'm not a designer ;)
我会使用
ItemsControl
。作为
ItemsPanel
,我将使用WrapPanel
。作为ItemTemplate
,您可以提供绑定到胶片图像的 DataTemplate,最好将图像提供为ImageSource
,然后您可以立即将其用作 Image 元素的源。为您的图像定义一个样式,在其中为每个 FrameworkElement 都有的
IsMouseOver
= true 定义一个触发器,无论您想要什么当鼠标悬停在图像上时的视觉效果。I would use an
ItemsControl
.As
ItemsPanel
I would use aWrapPanel
. AsItemTemplate
you can provide a DataTemplate binding to the Image of your Film, better provide the Image asImageSource
, then you can use it straight away as source for an Image element.Define a Style for your Image in which you define a Trigger for the
IsMouseOver
= true that every FrameworkElement has, whatever eye-candy you want when the mouse is over the image.啊,正忙着模拟一个例子:) 无论如何我都会发布它:我添加了一个投影,但你可以轻松地将其更改为发光。,C# 部分只是从旁边的文件夹填充文件名列表。EXE文件。
XAML:
C#:
Ah, was busy mocking up an example :) I'll post it anyway: I added a drop shadow but you can easily change it to a glow., and the C# part just populates a list of file names from a folder next to the .exe.
XAML:
C#: