Silverlight列表框抛出“值未落在预期范围内"即使是空的? [英] silverlight listbox throwing "value not fall in expected range" even when empty?

查看:169
本文介绍了Silverlight列表框抛出“值未落在预期范围内"即使是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以编程方式使用模板控件动态填充Silverlight列表框. 列表框为空,并且当我尝试使用listBox.Items.Add(myTemplateControl)时,它将引发值不在预期范围内"参数异常.

I'm dynamically populating a silverlight listbox, programmatically, with a template control. the listbox is empty, and when i attempt a listBox.Items.Add(myTemplateControl), it throws the "Value does not fall within the expected range" argumentexception.

我在调试器中确认项目集合确实为空. 我唯一一次听说发生这种异常的情况是,当列表中已经包含具有该名称的实例时.

i verified in the debugger that the item collection is indeed emtpy. the only time i've heard of this exception happening is when the list already contains an instance with that name.

有什么想法吗?

堆栈跟踪:


at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
at MS.Internal.XcpImports.Collection_Add[T](PresentationFrameworkCollection`1 collection, Object value)
at System.Windows.PresentationFrameworkCollection`1.AddImpl(Object value)
at System.Windows.Controls.ItemCollection.AddImpl(Object value)
at System.Windows.Controls.ItemCollection.AddInternal(Object value)
at System.Windows.PresentationFrameworkCollection`1.Add(T value)
at KTClientRIA.Documents.b__4(Object sender, DownloadStringCompletedEventArgs e)
at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)

推荐答案

感谢所有建议.我能够找到它.在Silverlight控件生命周期的另一个时间点,还有另一个与之完全不同的列表框,其中添加了一个相同名称的项目. 因为两个父列表框都驻留在同一个Silverlight控件上,所以它被炸掉了.

Thanks to all the suggestions. I was able to track it down. At another point in time of the life cycle of the silverlight control, there was another listbox completely separate from this one that was adding an item of the same name. being that both the parent listboxes resided on the same silverlight control, it was blowing up.

这篇关于Silverlight列表框抛出“值未落在预期范围内"即使是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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