property was already registered by 'FrameworkElement'

后端 未结 1 703
一个人的身影
一个人的身影 2020-12-10 01:29

I am writing two dependency properties and I keep getting the \"[Property] was already registered by \'FrameworkElement\'\" error in the design window of VS11. Here is a sn

1条回答
  •  醉酒成梦
    2020-12-10 02:07

    The third parameter ownerType of the DependencyProperty.Register method must be the class that declares the property.

    If your class is MyClass the declaration would have to look like this:

    public class MyClass : DependencyObject
    {
        public static readonly DependencyProperty IsEditingNumberProperty =
            DependencyProperty.Register(
                "IsEditingNumber", typeof(bool), typeof(MyClass), ...);
    
        // CLR wrapper
        public bool IsEditingNumber
        {
            get { return (bool)GetValue(IsEditingNumberProperty); }
            set { SetValue(IsEditingNumberProperty, value); }
        }
    }
    

    0 讨论(0)
提交回复
热议问题