Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 一个简单的图像列表视图_Wpf_Listview - Fatal编程技术网

Wpf 一个简单的图像列表视图

Wpf 一个简单的图像列表视图,wpf,listview,Wpf,Listview,我试图创建一个简单的字典绑定图像列表视图,其中键是文件名,值是图像路径 下面是代码 <ListView Grid.Column="2" Grid.Row="3" Height="131" HorizontalAlignment="Left" Margin="6,9,0,0" Name="GenreListView1" VerticalAlignment="Top" Width="375"> <ListView.ItemsPanel> <

我试图创建一个简单的字典绑定图像列表视图,其中键是
文件名
,值是
图像路径

下面是代码

<ListView Grid.Column="2" Grid.Row="3" Height="131" HorizontalAlignment="Left" Margin="6,9,0,0" Name="GenreListView1" VerticalAlignment="Top" Width="375">
    <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Horizontal"></WrapPanel>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
    <ListView.ItemTemplate>
    <DataTemplate>
        <Image Source="{Binding}"></Image>
    </DataTemplate>
</ListView.ItemTemplate>
                    </ListView>
你能告诉我如何把图片装订好吗。这是一个windows应用程序。

试试看

<Image Source="{Binding Value}"/>

你为什么要用字典?为什么不使用文件名列表呢?如果您这样做,那么您的
将起作用。您的代码将如下所示:

Dim maindir As DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(CurDir() + "\Icons")

Dim fileList = as new List<string>();

For Each k As FileInfo In maindir.GetFiles()
    If k.Name.EndsWith(".png") Then
        fileList.Add(k.FullName)
    End If
Next

'Load Icons to Genre View
GenreListView1.ItemsSource = fileList
Dim maindir As DirectoryInfo=My.Computer.FileSystem.GetDirectoryInfo(CurDir()+“\Icons”) Dim fileList=作为新列表(); 对于maindir.GetFiles()中的每个k As FileInfo 如果k.Name.EndsWith(“.png”),则 fileList.Add(k.FullName) 如果结束 下一个 '将图标加载到流派视图 GenreListView1.ItemsSource=文件列表
ArsenMkrt,谢谢你的快速回复,但是我现在还没有收到那份工作。谢谢,这工作很有魅力,但现在我又面临一个问题,所有图像都只排在一行,虽然有包装面板,但它们没有包装,我应该使用scrollview吗,我甚至试过了,但出现了一些错误,说面板只能放在模板中。你能在这方面帮助我吗?另一个答案可以帮助你:
Dim maindir As DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(CurDir() + "\Icons")

Dim fileList = as new List<string>();

For Each k As FileInfo In maindir.GetFiles()
    If k.Name.EndsWith(".png") Then
        fileList.Add(k.FullName)
    End If
Next

'Load Icons to Genre View
GenreListView1.ItemsSource = fileList