无法访问没有装饰器的元素上的装饰器
我尝试使用 MVVM 在 WPF 上进行一些拖放操作,
我从 Bea Stollnitz 找到了此链接 http://bea.stollnitz提出了一个解决方案 在这里使用 DragDropHelper : https://github.com/bstollnitz /old-wpf-blog/tree/master/46-DragDropListBox
但是当我尝试使用一些事件生成组件(例如按钮或数据模板中的单选按钮,我在拖动时遇到此错误drop
“无法访问没有装饰器的元素上的装饰器。”
在这一行
this.adornerLayer.Update(this.AdornedElement);
来轻松重现它
您可以通过下载 bea.stollnitz.com/files/46/DragDropListBox.zip并替换
<DataTemplate x:Key="pictureTemplate">
<DataTemplate.Resources>
<Style TargetType="Image">
<Setter Property="Width" Value="50" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="10" />
</Style>
</DataTemplate.Resources>
<Image Source="{Binding Path=Location}" />
</DataTemplate>
为
<DataTemplate x:Key="pictureTemplate">
<DataTemplate.Resources>
<Style TargetType="Image">
<Setter Property="Width" Value="50" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="10" />
</Style>
</DataTemplate.Resources>
<Grid>
<Image Source="{Binding Path=Location}" />
<RadioButton />
</Grid>
</DataTemplate>
ie 在模板中添加单选按钮
,我已经找到了一些链接,但没有一个链接解释了解决问题的明确方法。
建议添加此代码
VisualCollection视觉儿童; FrameworkElement @object;
public CustomAdorner(UIElement adornedElement) :
base(adornedElement)
{
visualChildren = new VisualCollection(this);
@object = new Button {Content = "prova"};
visualChildren.Add(@object);
}
protected override Visual GetVisualChild(int index)
{
return visualChildren[index];
}
但我确定在哪里添加它以及此链接的相同内容
提出
private bool IsItemDisconnected(object item)
{
bool isDisconnected = false;
var itemType = item.GetType();
if (itemType.FullName.Equals("MS.Internal.NamedObject"))
{
isDisconnected = true;
}
return isDisconnected;
}
最后一个链接讨论 .NET 4 问题,但我在 3.5 上也有这个错误
I try to make some drag&drop on WPF using MVVM
I found this link from Bea Stollnitz http://bea.stollnitz which propose a solution
with a DragDropHelper here : https://github.com/bstollnitz/old-wpf-blog/tree/master/46-DragDropListBox
but when i try to customize it with some events generating components such as button or radioButton in datatemplate, i have this error on drag & drop
"Cannot access adorners on element that has no adorners."
on this line
this.adornerLayer.Update(this.AdornedElement);
you can reproduce it easily by downloading bea.stollnitz.com/files/46/DragDropListBox.zip
and replacing
<DataTemplate x:Key="pictureTemplate">
<DataTemplate.Resources>
<Style TargetType="Image">
<Setter Property="Width" Value="50" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="10" />
</Style>
</DataTemplate.Resources>
<Image Source="{Binding Path=Location}" />
</DataTemplate>
by
<DataTemplate x:Key="pictureTemplate">
<DataTemplate.Resources>
<Style TargetType="Image">
<Setter Property="Width" Value="50" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="10" />
</Style>
</DataTemplate.Resources>
<Grid>
<Image Source="{Binding Path=Location}" />
<RadioButton />
</Grid>
</DataTemplate>
i.e. adding a radiobutton in the template
i already find some links but none of them explain a clear way to solve the issue.
No events passed to WPF adorner layer
that propose to add this code
VisualCollection visualChildren;
FrameworkElement @object;
public CustomAdorner(UIElement adornedElement) :
base(adornedElement)
{
visualChildren = new VisualCollection(this);
@object = new Button {Content = "prova"};
visualChildren.Add(@object);
}
protected override Visual GetVisualChild(int index)
{
return visualChildren[index];
}
but i'm sure where to add it and same thing for this link
that propose
private bool IsItemDisconnected(object item)
{
bool isDisconnected = false;
var itemType = item.GetType();
if (itemType.FullName.Equals("MS.Internal.NamedObject"))
{
isDisconnected = true;
}
return isDisconnected;
}
this last link talk about a .NET 4 issue but i also have the bug on 3.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想在这里发帖说我已经找到了解决方案。阅读拖放错误:无法访问后没有装饰器的元素上的装饰器
I wanted to post on here that I had found a solution to this. After reading Drag drop error : Cannot access adorners on element that has no adorners