我想做一個簡單的字典綁定圖像列表查看,其中的關鍵是filename
和值是image path
。簡單的圖像列表視圖
以下是代碼
<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>
以下爲運行代碼:
Dim maindir As DirectoryInfo = My.Computer.FileSystem.GetDirectoryInfo(CurDir() + "\Icons")
GenreDictionary.Clear()
For Each k As FileInfo In maindir.GetFiles()
If k.Name.EndsWith(".png") Then
GenreDictionary.Add(k.Name, k.FullName)
End If
Next
'Load Icons to Genre View
GenreListView1.ItemsSource = GenreDictionary.Values
可否請你指導我如何獲得綁定的圖像。這是一個Windows應用程序。
謝謝,這個作品像一個魅力,但現在我面臨一個更多的問題,所有的圖像只排成一行,雖然包裝面板在那裏,他們不包裝,我應該使用scrollview,我甚至嘗試過但是一些錯誤即將出現,稱面板只能放在模板中。你能幫我解決這個問題嗎? – surpavan
這個其他答案可以幫助你:http://stackoverflow.com/questions/1041551/wpf-listview-with-horizontal-arrangement-of-items –