无法从Windows Phone 8.1中的ListView控件中删除项目

时间:2016-03-21 09:54:34

标签: c# xaml listview windows-phone-8.1

我正在尝试使用listview函数从RemoveAt()控件中删除某个项,但是我收到以下错误:

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

我使用以下代码删除项目:

void remove (object sender)
{
    var item = (sender as FrameworkElement).DataContext;
    int index = PropSearchList.Items.IndexOf(item);
    PropSearchList.Items.RemoveAt(index);
}

1 个答案:

答案 0 :(得分:1)

在UI线程中执行此操作

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

UPDATE:

您可以使用ObservableCollection并从源中删除项目。为cachedData创建一个实例并重写来代码:

private ObservableCollection<T> cachedData;
...
PropSearchList.ItemsSource = cachedData;
...
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => cachedData.RemoveAt(index));