且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我看到“成员无法识别或无法访问"?我的 WPF 用户控件出错?

更新时间:2023-12-01 17:38:04

您需要将您的属性声明为 Dependency Properties

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