I am trying to make a simple dictionary bound image listview where key is filename and value is image path.
Following is the code
<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>
Following is the code for runtime:
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
Could you please guide me on how to get the image bound. This is a windows app.
Why are you using a dictionary? Why not just use a list of FileNames? If you do that then your
<Image Source="{Binding"} />would work. Your code would then look like this: