0

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

EasyBB
  • 6,176
  • 9
  • 47
  • 77
  • When declaring an element in XAML the string before the `:` is supposed to be the [NameSpace](https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/xaml-namespaces-and-namespace-mapping-for-wpf-xaml) where the class is declared. You have `UserControl:Icomoon`, is `UserControl` the label you gave to your namespace? – Keith Stein Jan 02 '20 at 19:15
  • Yes it is the label – EasyBB Jan 02 '20 at 19:16
  • `UserControl:Icomoon` => `local:Icomoon` – Trevor Jan 02 '20 at 19:17
  • I also see that your DependencyProperty is registered as a `string`, but the normal property is an `object`. Maybe that has something to do with it? – Keith Stein Jan 02 '20 at 19:18
  • Keith I had it originally an object then switched to string to see if that worked. I'll retry object for giggles. – EasyBB Jan 02 '20 at 19:19
  • @KeithStein `object` has `ToString`, doesn't matter in this case as it's a string. – Trevor Jan 02 '20 at 19:20
  • Codexer I don't have a local. I separate most of the stuff for naming conventions. Ideas of constantly labeling local: button or local:resource etc. I have a few higher folders that I keep everything in to keep it clean and conventional. Just the way I like to do stuff – EasyBB Jan 02 '20 at 19:21
  • @EasyBB understand, the point already mentioned though is the namespace that control lives in, for testing, mine was local. – Trevor Jan 02 '20 at 19:25
  • Copying your code into a new project doesn't give the same error on my end. Does the code run and work for you even though it's giving an error in Visual Studio? – Keith Stein Jan 02 '20 at 19:28
  • Keith after trying to run it, it ran and the error went away... What is up with that? – EasyBB Jan 02 '20 at 19:31
  • Dumb question, did you do a clean & re-build? Sometimes those DP can be strange in UC... – Trevor Jan 02 '20 at 19:31
  • Yeah cleaned solution and cleaned the build. Then rebuilt everything – EasyBB Jan 02 '20 at 19:33
  • 1
    So you rebuilt and the error was still there, but then you ran it and it went away? Go figure. Well, at least it's gone now. – Keith Stein Jan 02 '20 at 19:34
  • yeah. of course, the programmer's way, when you fix one error two more arise. – EasyBB Jan 02 '20 at 19:38

1 Answers1

0

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 
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122