我正在尝试清除 Windows RT 应用程序中列表框的项目。要添加项目,我使用:
List<string> list1;
...
foreach(string s in list1.Items)
{
listBox1.Items.Add(s);
}
要清除这些项目,我使用:
listBox1.Items.Clear();
但是,这会引发此异常:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
如果我尝试使用:
int at = 0;
while (at < listBox1.Items.Count)
{
listBox1.Items.RemoveAt(at);
at += 1;
}
我在 RemoveAt 方法中遇到相同的异常。
我找到了这个问题的解决方案。我试图从 SelectionChanged 事件触发的方法中删除项目。我将其更改为:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, listBox1.Items.Clear);
而且效果很好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)