小编Lui*_*shg的帖子

C#WPF附加属性 - 错误:"XML名称空间中不存在该属性"

我需要为现有的WPF控件(Groupbox,文本框,复选框等)创建一个新属性,这个控件将存储其访问级别,因此我找到了附加属性.我以此网站为例http://dotnetbyexample.blogspot.com.br/2010/05/attached-dependency-properties-for.html

一切都很好,但是当我尝试在某些控件上使用它时,我得到了以下错误...

错误1 XML命名空间'clr-namespace中不存在属性'DependencyPropertiesHoster.AcessLevel':ImageGUI.App_Code; assembly = ImageGUI'.第131行位置97. ImageGUI\MainWindow.xaml 131 97 ImageGUI

这是我的C#代码片段......

namespace ImageGUI.App_Code
{    
    public static class DependencyPropertiesHoster
    {
    //[AttachedPropertyBrowsableForChildren]
    public static readonly DependencyProperty AcessLevelProperty =
      DependencyProperty.RegisterAttached("AcessLevel",
      typeof(EAcessLevel),
      typeof(DependencyPropertiesHoster),
      new PropertyMetadata(AcessLevelChanged));

    // Called when Property is retrieved
    public static EAcessLevel GetAcessLevel(DependencyObject obj)
    {
        if (obj != null)
            return (EAcessLevel)obj.GetValue(AcessLevelProperty);
        else
            return EAcessLevel.Client;
        //return obj.GetValue(AcessLevelProperty) as EAcessLevel;

    }

    // Called when Property is set
    public static void SetAcessLevel(
       DependencyObject obj,
       EAcessLevel value)
    {
        obj.SetValue(AcessLevelProperty, value);
    }

    // Called when …
Run Code Online (Sandbox Code Playgroud)

c# wpf dependencies dependency-properties attached-properties

16
推荐指数
1
解决办法
4686
查看次数