【问题标题】:Member is not recognized or accessible WPF成员无法识别或无法访问 WPF
【发布时间】:2020-01-02 19:06:08
【问题描述】:

所以我知道这个问题已经被问过很多次了,我已经阅读了大约 10 篇关于这个问题的帖子。我已重新启动 Visual Studios,但仍然出现错误。

The Member IcoIcon is not recognized or accessible 

这是我的代码

 public partial class Icomoon : UserControl
    {

        public static readonly DependencyProperty IcoIconProperty =
            DependencyProperty.Register("IcoIcon", typeof(string), typeof(Icomoon), new PropertyMetadata(null));

        public object IcoIcon
        {
            get => (string)GetValue(IcoIconProperty);
            set => SetValue(IcoIconProperty, IcoMoonVariables.Invoke((string)value));
        }

        public Icomoon()
        {
            InitializeComponent();
        }
    }

因此,据我所知,我已正确注册它,并且当我输入它时它会显示在 Intellisense 中。但它仍然给我错误。

<UserControl:Icomoon IcoIcon="LineGraph" />

我是否忽略了成员的班级名称?我已经研究了一段时间,所以任何方向感都会有所帮助。建议赞赏

【问题讨论】:

  • 在 XAML 中声明元素时,: 之前的字符串应该是声明类的NameSpace。你有UserControl:IcomoonUserControl 是你给命名空间的标签吗?
  • 是的,它是标签
  • UserControl:Icomoon => local:Icomoon
  • 我还看到您的 DependencyProperty 注册为 string,但普通属性是 object。也许这与它有关?
  • 所以你重建并且错误仍然存​​在,但是你运行它并且它消失了?去搞清楚。好吧,至少它现在已经消失了。

标签: c# wpf dependency-properties


【解决方案1】:

为什么不将Object 指定为一个值类型呢?引用依赖属性不同于值 1。

因为它是一个字符串,所以指定它并将空条件设置为string.empty 而不是空 例如:

    #region public string IcoIcon

    public string IcoIcon
    {
        get { return (string)GetValue(IcoIconProperty); }
        set { SetValue(IcoIconProperty, value); }
    }

    /// <summary>
    /// Identifies the IcoIcon dependency property.
    /// </summary>
    public static readonly DependencyProperty IcoIconProperty =
        DependencyProperty.Register(
            "IcoIcon",
            typeof(string),
            typeof(MainWindow),
            new PropertyMetadata(string.Empty));
    #endregion public string IcoIcon 

【讨论】:

    猜你喜欢
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多