简体   繁体   中英

Member is not recognized or accessible WPF

So I know this has been asked many times, I've read about 10 post with this issue. I've restarted Visual Studios and I'm still getting the error.

The Member IcoIcon is not recognized or accessible 

Here is my code

 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();
        }
    }

So from what I can tell is I registered it properly, and it is showing up in the Intellisense when I type it out. But then it still gives me the error.

<UserControl:Icomoon IcoIcon="LineGraph" />

Am I overlooking a member's class names? I've been looking over this for some time so any sense of direction would be helpful. Suggestions appreciated

Instead of Object why not specify it as a value type through and through? A reference dependency property is different from a value one.

Since its a string, specify it as such and set the empty condition to string.empty and not null such as:

    #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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM