我正在尝试使用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);
}
答案 0 :(得分:1)
在UI线程中执行此操作
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => PropSearchList.Items.RemoveAt(index));
您可以使用ObservableCollection
并从源中删除项目。为cachedData
创建一个实例并重写来代码:
private ObservableCollection<T> cachedData;
...
PropSearchList.ItemsSource = cachedData;
...
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => cachedData.RemoveAt(index));