Unable to remove Item from ListView control in Windows Phone 8.1

1

I am trying to remove an item from listview control using RemoveAt() function but I am getting the following error:

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

I am using the following code to remove item:

void remove (object sender)
{
    var item = (sender as FrameworkElement).DataContext;
    int index = PropSearchList.Items.IndexOf(item);
    PropSearchList.Items.RemoveAt(index);
}
c#
xaml
listview
windows-phone-8.1
asked on Stack Overflow Mar 21, 2016 by Bilal Amjad • edited Mar 21, 2016 by Guy

1 Answer

1

Just do it in UI thread

Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => PropSearchList.Items.RemoveAt(index));

UPDATE:

You can use ObservableCollection and remove items from your source. Create an instance for your cachedData and rewrite come code:

private ObservableCollection<T> cachedData;
...
PropSearchList.ItemsSource = cachedData;
...
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => cachedData.RemoveAt(index));
answered on Stack Overflow Mar 21, 2016 by Andrii Krupka • edited Mar 21, 2016 by Andrii Krupka

User contributions licensed under CC BY-SA 3.0