无法识别成员或无法访问WPF

问题描述 投票:0回答:1

所以我知道这已经被问过很多次了,我已经读了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" />

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

c# wpf dependency-properties
1个回答
0
投票

而不是Object,为什么不将其始终指定为值类型?引用依赖项属性与值一不同。

由于其为字符串,因此将其指定为空,并将空条件设置为string.empty 且不为null,例如:

    #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 
© www.soinside.com 2019 - 2024. All rights reserved.