不能说没有装饰器
问题描述:
我尽量让WPF的一些阻力&使用一滴MVVM不能说没有装饰器
我发现从比亚Stollnitz http://bea.stollnitz它提出了一个解决方案 与这里DragDropHelper这个链接元素的装饰器访问。 COM /文件/ 46/DragDropListBox.zip
但是当我尝试了一些事件产生的组件,如DataTemplate中按钮或单选按钮来定制它,我已经拖&下降这个错误
“无法在访问装饰器元素没有装饰者。“
该线路上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>
<Grid>
<Image Source="{Binding Path=Location}" />
<RadioButton />
</Grid>
</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>
<Image Source="{Binding Path=Location}" />
</DataTemplate>
中添加一个单选按钮,轻松地重现模板
我已经找到一些链接,但没有一个解释cle解决问题的方法。
No events passed to WPF adorner layer
该建议添加此代码
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];
}
,但我敢肯定,在那里将其添加和同样的事情这个链接
是提出关于.NET 4的问题
private bool IsItemDisconnected(object item)
{
bool isDisconnected = false;
var itemType = item.GetType();
if (itemType.FullName.Equals("MS.Internal.NamedObject"))
{
isDisconnected = true;
}
return isDisconnected;
}
这最后一个环节谈话但我也有3.5的错误
答
我想发布在这里,我已经找到这是一个解决方案。阅读后Drag drop error : Cannot access adorners on element that has no adorners
if (this.adornerLayer != null && this.contentPresenter.Content != null)
{
this.adornerLayer.Update(this.AdornedElement);
}
所以没有人似乎受到我的问题的启发。我发现了另一个bea stollnitz解决方案的实现。使用http://www.codeproject.com/KB/WPF/gong-wpf-dragdrop.aspx,我终于用事件生成模板进行拖放。这个解决方案看起来更像是解决方案背后的代码,而不是真正的mvvm代码(因为我们直接通过在视图模型中拖放事件来进行管理),但它的工作原理没有缺陷,并且具有另一个优点,可以对丢弃的项目进行排序。 – Pansoul 2012-01-09 13:20:16
你有没有找到解决这个问题的方法?我有同样的问题,我认为相同的代码。 – 2012-11-21 21:30:11