显示项目在一个WPF ListView中的图像 [英] Showing items as images in a WPF ListView

查看:990
本文介绍了显示项目在一个WPF ListView中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,我已绑定一个列表的ListView 其中列表的类型是专辑,它有很多特性,包括设备罩起来,我是一个的项目图像在磁盘上。嗯,因为我不知道是什么类型的图像是必要的,它们是如何被加载(我只知道用图片类型的WinForms),我不知道类型呢。

有人可以显示或张贴我一个快速的样品,其中就说明这类物品被显示为用他们的设备罩起来属性某一固定大小的图像?

在本质上,这将显示:

  1. 在什么类型的设备罩起来
  2. 如何从磁盘WPF打开图像(假设它比的WinForms图像加载不同)
  3. 如何向他们展示在一个ListView作为某些固定大小的图片,缩放图像如有必要
解决方案
  1. 的ImageSource
  2. 的ImageSource myImageSource =新的BitmapImage(新的URI(@文件:// C:... something.jpg));
  3. 指定的ListView的ItemTemplate属性的项目的数据模板:

     < Window.Resources>
        < D​​ataTemplate中X:关键=ItemTemplate中>
            < StackPanel的方向=横向>
                <图像宽度=10高度=10弹力=填充来源={装订封面}/>
            <标签内容={结合标题}/>
            < / StackPanel的>
        < / DataTemplate中>
    < /Window.Resources>
    
    
    <电网X:名称=网格>
        < ListView控件的ItemTemplate ={的StaticResource的ItemTemplate}的ItemsSource ={结合相册}/>
    < /网格>
     

So I have binded a List to a ListView where the List has items of type Album, where it has lots of properties including .Cover, which I is an image on disk. Well since I don't know what type of image is needed and how they have to be loaded (I only know using Image types for Winforms), I don't know the type yet.

Can someone show or post me a quick sample where it shows this sort of items being shown as images of a certain fixed size using their .Cover property?

In essence this would show:

  1. What type .Cover should be
  2. How to open images from disk for WPF (assuming it's different than Winforms image loading)
  3. How to show them on a ListView as images of a certain fixed size, scaling the images if necessary

解决方案

  1. ImageSource
  2. ImageSource myImageSource = new BitmapImage(new Uri(@"file://C:... something.jpg"));
  3. Specify a data template for the items in the ListView's ItemTemplate property:

    <Window.Resources>
        <DataTemplate x:Key="ItemTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Width="10" Height="10" Stretch="Fill" Source="{Binding Cover}"/>
            <Label Content="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    
    
    <Grid x:Name="grid">
        <ListView ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Albums}" />
    </Grid>
    

这篇关于显示项目在一个WPF ListView中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆