I am working on a program that shows users all the pages they scanned, and allows them to re-scan a page if they aren't happy with it. I made a small preview of the pages with a listview that shows thumbnails of the images.
When I re-scan a page, the old preview thumbnail isn't deleted, and the new one appears besides it. My code replaces the old image by a new one with the same name.
Any ideas on how to solve this ? It doesn't seem like I can delete it by index or refresh the view to fix it. I could re-load all the images, but I'm concerned about performance when I have more than 20 images. If I have less than 11 images (0 to 9) I don't encounter this problem.
XAML of the ListView :
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Image Source="{Binding image}"
HorizontalAlignment="Center" VerticalAlignment="Top" Stretch="Fill" />
<TextBlock Text="{Binding titre}"
HorizontalAlignment="Center" VerticalAlignment="Bottom" />
<TextBlock Text="{Binding index}" Visibility="Visible"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
This code replaces the correct image :
private void UpdateListePreview(int index)
{
if (index >= 0 && index < imagelist.Count)
{
imagelist[index] = controleur.ChargerImageSelectionnee(index, 320, 480);
listePreview.SelectedIndex = index;
}
}
This code adds images in the ObservableCollection :
imagelist = new ObservableCollection<ImageData>();
foreach(ImageData data in controleur.ChargerImages())
{
imagelist.Add(data);
}
listePreview.ItemsSource = imagelist;