XML 命名空间中不存在该属性
我目前正在努力为我们公司的应用程序启用拖放支持。
我不断收到的错误对我来说似乎很奇怪。
这说明的是,
The property 'DragDropHelper.IsDragSource' does not exist in XML namespace 'clr-namespace:DragAndDrop;assembly=DragAndDrop'. Line 61 Position 83
该属性是我在示例中在互联网上找到的类中的附加属性,并对其进行了一些修改。这是属性声明:
namespace DragAndDrop {
public class DragDropHelper
{
public static readonly DependencyProperty IsDragSourceProperty =
DependencyProperty.RegisterAttached("IsDragSource", typeof (bool), typeof (DragDropHelper),
new UIPropertyMetadata(false, IsDragSourceChanged));
public static bool GetIsDragSource(DependencyObject obj)
{
return (bool) obj.GetValue(IsDragSourceProperty);
}
public static void SetIsDragSource(DependencyObject obj, bool value)
{
obj.SetValue(IsDragSourceProperty, value);
}
在我看来,附加属性是完全有效的,不是吗? 这个 DragDropHelper 包含在一个类库中,我从主客户端应用程序中引用了该类库。 当我尝试在客户端应用程序中设置属性的值时:
<ListView x:Uid="list" x:Name="CurrentFolderItemsControl" drag:DragDropHelper.IsDragSource="true" />
VS2010 表示 XML 命名空间中不存在该属性。 XAML文档是一个资源字典 它被合并到主客户端应用程序资源中,因为它包含我们控件的样式。
这更奇怪,因为我在主应用程序中创建了一个具有附加属性的类,然后在 XAML 标记中设置属性值 - 应用程序编译正常
I'm currently working on enabling drag-and-drop support for our company app.
The error I keep getting seems weird to me.
What this says is that
The property 'DragDropHelper.IsDragSource' does not exist in XML namespace 'clr-namespace:DragAndDrop;assembly=DragAndDrop'. Line 61 Position 83
The property is an attached property in the class I found in the Internet in the samples and modified it a bit. Here is property declaration:
namespace DragAndDrop {
public class DragDropHelper
{
public static readonly DependencyProperty IsDragSourceProperty =
DependencyProperty.RegisterAttached("IsDragSource", typeof (bool), typeof (DragDropHelper),
new UIPropertyMetadata(false, IsDragSourceChanged));
public static bool GetIsDragSource(DependencyObject obj)
{
return (bool) obj.GetValue(IsDragSourceProperty);
}
public static void SetIsDragSource(DependencyObject obj, bool value)
{
obj.SetValue(IsDragSourceProperty, value);
}
It seems to me that attached property is completely valid, isn't it?
This DragDropHelper is included into a class library, that I reference from the main client app.
When I try to set the value of the property in a client app:
<ListView x:Uid="list" x:Name="CurrentFolderItemsControl" drag:DragDropHelper.IsDragSource="true" />
VS2010 says that property doesn't exist in XML namespace. The XAML document is a resource dictionary
which is merged into main client app resources, because it contains styles for our control.
It's even more weird because I created a class within main app that has attached property, then set property value in XAML markup - app compiled OK
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
对死灵感到抱歉...只是想分享一下在我的类似场景中发生的事情。我从外部项目复制了我的视图,该项目在内部引用了行为的命名空间:
要使其工作,需要发生两件事。首先,xmlns 需要显式引用行为类的程序集,如下所示:
其次,我暂时删除了第二行并首先重建了我的解决方案。当您克隆 WPF 项目时,VS2012 有时会陷入困境,而良好的 Clean &没有违规行的重建通常可以解决问题(在我再次添加该行后,它识别出了该行为)。
Sorry for the necro... just thought I'd share what happened in my similar scenario. I copied my View from an external project, which referenced the behaviour's namespace internally:
Two things needed to happen for this to work. Firstly, the xmlns needed to explicitly reference the assembly for the behaviour class, like so:
Secondly, I temporarily removed the second line and rebuilt my solution first. VS2012 sometimes gets its knickers in a knot when you clone WPF projects, and a good Clean & Rebuild without the offending line often fixes things (it recognised the behaviour after I added the line back again).
问题解决了。我的错误是我在添加附加属性后没有重新编译库。在我这样做之后,一切都按预期进行。对不起大家:(
Problem solved. My error was I didn't recompile the library after having added attached property. After I did so, everything works as expected. Sorry everybody :(
我遇到了和你完全相同的问题。我通过将
[AttachedPropertyBrowsableForChildren]
属性放置在我的 setter 方法上方来使其工作。不要问我为什么,它只是有效......I had exactly the same problem as you did. I got it to work by placing the
[AttachedPropertyBrowsableForChildren]
attribute above my setter method. Don't ask me why, it just worked...在定义处理程序之前定义控件(在我的例子中为按钮)时,我收到此错误。在创建清除错误的方法后,我必须删除该按钮并重新定义它。
I got this error when I defined the control (button in my case) before defining the handler. I had to delete the button and redefine it after creating the method to clear the error.