拖放错误:无法访问没有装饰器的元素上的装饰器
我正在实施此处提到的拖放解决方案:
http://bea.stollnitz.com/blog/ ?p=53
我有一些带有 WrapPanel
和 Items 的 ListBox
es + 。我应该能够将项目从任何一个框中拖放到任何其他框中。
当我拖动一个项目并将其移动到另一个框时,它会抛出错误:
无法访问没有装饰器的元素上的装饰器。
在这一行:
if (this.adornerLayer != null)
{
this.adornerLayer.Update(this.AdornedElement);
}
我试图查看 AdornedElement 的值,我看到它具有以下值:
ListBoxItem : DisconnectedItem
。我看到了 ListBoxItem
的内容,似乎它也有断开连接的项目。
如果我在同一列表框中移动我的项目,也会出现此问题。我的列表框使用wrapPanel 作为ItemsPanelTemplate
。
层次结构树就像这样,列表框是:
1 列表框: 用户控制 边界 网格 网格 边界 边界 边界 滚动查看器 列表框 ItemsPanel
其他 3 个列表框: 用户控制 边界 网格 网格 网格 选项卡控件 选项卡项 网格 边界 边界 边界 滚动查看器 列表框 ItemsPanel
有谁遇到过这个问题或者可以帮我看看出了什么问题吗?
- 吉里贾
I am implementing the Drag drop solution mentioned here :
http://bea.stollnitz.com/blog/?p=53
I have few ListBox
es + with WrapPanel
and Items. i should be able to drag and drop item from any of the boxes to any other.
When I drag an item and move it across to another box, it throws me error:
Cannot access adorners on element that has no adorners.
at this line :
if (this.adornerLayer != null)
{
this.adornerLayer.Update(this.AdornedElement);
}
I tried to see the value of AdornedElement i saw that it has this value :
ListBoxItem : DisconnectedItem
. I saw the Content of ListBoxItem
and seems it also has disconnected item.
The issue also happens if i move my items withing the same listbox. My listbox uses a wrapPanel as ItemsPanelTemplate
.
the hierarch tree is like this of teh listBoxes are :
1 List box :
UserControl
Border
Grid
Grid
Border
Border
Border
ScrollViewer
ListBox
ItemsPanel
Other 3 ListBoxes :
UserControl
Border
Grid
Grid
Grid
tabControl
tabItem
Grid
Border
Border
Border
ScrollViewer
ListBox
ItemsPanel
AnyOne who has faced this issue or can help me what is going wrong ?
- Girija
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也能够重现这个问题。我能够通过将代码行更改为以下内容来防止错误停止:
I was able to reproduce this issue as well. I was able to prevent the error stop by changing the line of code to this:
这是 .Net 4.0 错误
http://social.msdn.microsoft.com/Forums/en/wpf/thread/e6643abc-4457-44aa-a3ee-dd389c88bd86?prof=required
您也可能会在选项卡中看到此内容控制。
每当某些东西没有真正显示时,一旦你脱离了视觉树,你的绑定就会变得混乱。
this is a .Net 4.0 bug
http://social.msdn.microsoft.com/Forums/en/wpf/thread/e6643abc-4457-44aa-a3ee-dd389c88bd86?prof=required
you may also see this in tab controls.
Any time something is not displayed really, once your fall out of the visual tree your bindings can get messed up.
jhamm 建议尝试的方法,不幸的是,它不适用于我的情况。我最终修改了微软论坛上的线程中建议的代码,如上所述:
检查
当项目断开连接时
失败。顺便说一句,据报道该错误已在 4.5 中修复
Tried approach jhamm suggested, unfortunately, it does not work for my case. I ended up modifying code that was suggested in thread on microsoft forum, mentioned above :
The check
fails when the item is disconnected.
By the way the bug reported to be fixed in 4.5
在调用 Update() 之前检查是否可以找到 UIElement 的装饰层对我有用。
It worked for me to check if the adornerlayer for the UIElement could be found before calling Update().