WPF中的图像列表视图 [英] Images in listview WPF

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

问题描述

我想显示给定路径中的所有文件,包括图标图像或更好的图像,如何安排何时显示哪个图像?
正如您在下面的列表中看到的那样,列表中的每个项目(.pdf,.doc,.zip)都有一个单词图标.

链接到图像文件(这是我停止的地方)

I want to show all files from a given path, including the icon images or better yet, how can I arrange when should be shown which image ?
As you can see in the list below, there is a word icon for every item in the list (.pdf, .doc, .zip)

Link to image file (this is where i stopped)

推荐答案

这是一个非常开放的问题.您将要使用ListView的DataTemplate.绑定到ViewModel中的集合.该集合可以是字符串,然后使用Converter来使用正确的模板,或者您可以拥有一个集合,该集合是一个包含文件名和图像(或图像路径)的类.

这是可能的XAML:
This is a very open ended question. You will want to use a ListView a DataTemplate. Bind to a collection in the ViewModel. The collection could be string, and then use a Converter to use the correct template, or you can have a collection that is a class that contains the name of the file and the image (or path to the image.

Here is possible XAML:
<ListBox  ItemsSource="{Binding Path=FileNames}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" >
                <Image Source="{Binding ImagePath}" />
                <TextBlock Text="{Binding FileName}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>



由于必须创建ViewModel并填充它,因此还有很多工作要做.



There is still a lot of work to do since you have to create the ViewModel, and fill it.


我找到了另一种解决方案...我将列表视图替换为webbrowser控件,它显示了目录浏览以及文件中的图标,基本上就是这样,现在我只需要做一些其他的调整即可:)
I found another solution... I replaced the listview with the webbrowser control, it shows direcotry browsing and also the icons od the files, basically thats it, now I just have to do some more tweaking :)


这里是我的预览方式(关于这个问题) )
Here is a preview of the way I did it (regarding the question)
<listview x:name="listView" selectionmode="Single" scrollviewer.cancontentscroll="True" scrollviewer.verticalscrollbarvisibility="Auto" cursor="Arrow" verticalcontentalignment="Top" mousedoubleclick="listView_MouseDoubleClick" xmlns:x="#unknown">
                    <listview.view>
                        <gridview allowscolumnreorder="False">
                            <gridview.columnheadercontainerstyle>
                                <style>
                                    <!--<Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>-->
                                </style>
                            </gridview.columnheadercontainerstyle>
                            <gridviewcolumn>
                                <gridviewcolumnheader>
                                </gridviewcolumnheader>
                                <gridviewcolumn.celltemplate>
                                    <datatemplate>
                                        <stackpanel orientation="Horizontal">
                                            <image height="40" source="/Slike/word.png" />
                                        </stackpanel>
                                    </datatemplate>
                                </gridviewcolumn.celltemplate>
                            </gridviewcolumn>
                            <gridviewcolumn />
                        </gridview>
                    </listview.view>
                </listview>


这篇关于WPF中的图像列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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