删除从列表框中的某个项目会导致灾难性的失败? [英] Remove an item from a list box causes a Catastrophic Failure?

查看:119
本文介绍了删除从列表框中的某个项目会导致灾难性的失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Windows RT应用清除列表框中的项目。要添加的项目,我使用的:

I am trying to clear a list box's items in my Windows RT App. To add the items, I use:

List<string> list1;
...
foreach(string s in list1.Items)
{
    listBox1.Items.Add(s);
}

要清除的项目,我使用的:

To clear the items, I use:

listBox1.Items.Clear();



不过,这将引发此异常:

However, this throws this exception:

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

如果我尝试使用:

        int at = 0;
        while (at < listBox1.Items.Count)
        {
            listBox1.Items.RemoveAt(at);
            at += 1;
        }



我得到的RemoveAt移除方法相同的异常。

I get the same exception at the RemoveAt method.

推荐答案

我找到了解决这一问题。我试图从SelectionChanged事件发射的方法删除项目。我把它改为:

I found the solution to this problem. I was trying to remove items from a method fired by the SelectionChanged event. I changed this to:

await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, listBox1.Items.Clear);

和它工作正常。

这篇关于删除从列表框中的某个项目会导致灾难性的失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆