0

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.

Example of what the preview looks like, the new image is in color.

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;
dhilmathy
  • 2,800
  • 2
  • 21
  • 29
Lap
  • 31
  • 10
  • See here: https://stackoverflow.com/a/30164258/1136211 – Clemens Jul 30 '18 at 18:18
  • Oh I remember this, I had to cache the images in order for them to not be occupied by a part of the program, any idea on how I can erase a specific image from the cache ? – Lap Jul 30 '18 at 18:25
  • I fixed the issue, I used another method to add items to the listview that allows me to replace them directly. – Lap Aug 02 '18 at 13:19

0 Answers0