We shall use MVVM for this.
First we will make a model.
public class MyModel
{
public BitmapSource Picture { get; set; }
public string Description { get; set; }
}
Then our ViewModel
public class MyViewModel
{
public ObservableCollection<MyModel> Images { get; set; }
public ICommand ButtonClicked { get; set; }
... Logic to populate the images
}
And then our view
<Window x:Class="TestWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="clr-namespace:TestWPF"
Title="MainWindow"
Height="350"
Width="525">
<Window.Resources>
<loc:MyViewModel x:Key="ViewModel" />
</Window.Resources>
<Grid DataContext="{StaticResource ViewModel}">
<ListView ItemsSource="{Binding Images}">
<ListView.ItemTemplate>
<DataTemplate>
<Button Command="{Binding ButtonClicked, RelativeSource=Parent}"
CommandParameter="{Binding Description}">
<Image Width="50"
Height="50"
Source="{Binding Picture}"></Image>
</Button>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
That will create a list that should act in the same way.