XML 命名空间中不存在该属性

发布于 2024-09-28 23:19:55 字数 1302 浏览 5 评论 0原文

我目前正在努力为我们公司的应用程序启用拖放支持。
我不断收到的错误对我来说似乎很奇怪。
这说明的是,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

对死灵感到抱歉...只是想分享一下在我的类似场景中发生的事情。我从外部项目复制了我的视图,该项目在内部引用了行为的命名空间:

xmlns:b="clr-namespace:MyCompany.Common.Behaviours"
b:WindowBehaviours.Close="{Binding ClosingView}"

要使其工作,需要发生两件事。首先,xmlns 需要显式引用行为类的程序集,如下所示:

xmlns:b="clr-namespace:MyCompany.Common.Behaviours;assembly=Common"

其次,我暂时删除了第二行并首先重建了我的解决方案。当您克隆 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:

xmlns:b="clr-namespace:MyCompany.Common.Behaviours"
b:WindowBehaviours.Close="{Binding ClosingView}"

Two things needed to happen for this to work. Firstly, the xmlns needed to explicitly reference the assembly for the behaviour class, like so:

xmlns:b="clr-namespace:MyCompany.Common.Behaviours;assembly=Common"

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).

一笔一画续写前缘 2024-10-05 23:19:55

问题解决了。我的错误是我在添加附加属性后没有重新编译库。在我这样做之后,一切都按预期进行。对不起大家:(

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 :(

爱格式化 2024-10-05 23:19:55

我遇到了和你完全相同的问题。我通过将 [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...

梦罢 2024-10-05 23:19:55

在定义处理程序之前定义控件(在我的例子中为按钮)时,我收到此错误。在创建清除错误的方法后,我必须删除该按钮并重新定义它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文