Why am I seeing a "member is not recognized or is not accessible" error on my WPF User Control?

Visual Studio 2017

I had exactly the same problem. It was compiling one day ... and then it wasn't. I wasn't using DependencyProperty which shouldn't be needed as above. The properties were appearing in Intellisense but gave the same message when inserted. I cleaned, built, rebuilt, restarted VS, rebooted etc. All to no avail.

Last ditch try ... I removed all the offending attributes and got a clean compile. Then I put them back and it compiled. I really wasn't expecting that. Somehow VS had gotten its knickers in a twist.


If you are using VS2017, try to delete bin and obj folders in all projects of your solution, clean the solution and build again. It works for me !


You need to declare your property as Dependency Properties

namespace MyProject.Controls
{
    public partial class TestControl : UserControl
    {
        //Register Dependency Property

        public static readonly DependencyProperty TestMeDependency = DependencyProperty.Register("MyProperty", typeof(string), typeof(TestControl));

        public string MyCar
        {
            get
            {

                return (string)GetValue(TestMeDependency);

            }
            set
            {
                SetValue(TestMeDependency, value);
            }
        }

        public TestControl()
        {
            InitializeComponent();
        }
    }
}

Tags:

C#

Wpf

Xaml