【问题标题】:Unable to remove Item from ListView control in Windows Phone 8.1无法从 Windows Phone 8.1 中的 ListView 控件中删除项目
【发布时间】:2016-03-21 09:54:34
【问题描述】:

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

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);
}

【问题讨论】:

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


    【解决方案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));
    

    【讨论】:

    • 如何将ItemsSource 属性设置到 ListView?
    • 我正在使用 Q42 库缓存数据,然后分配数据,例如: var cachedData = await DataCache.GetAsync("FavouritesList", () => LoadData(SearchData)); PropSearchList.ItemsSource = cachedData;
    • Afaik 你几乎不应该使用高优先级,在这种情况下它似乎完全没有必要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多