小编Adr*_*cia的帖子

WPF:自定义控件属性已被另一个自定义控件错误注册

我创建了两个完全相同的自定义控件,只是它们属于两种不同的类型。

控制一

public class ControlOne : TextEdit
    {
        public static readonly DependencyProperty AwesomeSauceProperty =
         DependencyProperty.Register("AwesomeSauce", typeof(string), typeof(FormTextEditInput));           

        public string AwesomeSauce
        {
            get { return GetValue(AwesomeSauceProperty) as string; }
            set { SetValue(AwesomeSauceProperty, value); }
        }

    }
Run Code Online (Sandbox Code Playgroud)

控制二

public class ControlTwo : PasswordEdit
        {
            public static readonly DependencyProperty AwesomeSauceProperty =
             DependencyProperty.Register("AwesomeSauce", typeof(string), typeof(FormTextEditInput));           

            public string AwesomeSauce
            {
                get { return GetValue(AwesomeSauceProperty) as string; }
                set { SetValue(AwesomeSauceProperty, value); }
            }

        }
Run Code Online (Sandbox Code Playgroud)

在 XAML 中,我只是这样做

<controls:ControlOne AwesomeSauce="Yummy"/>
<controls:ControlTwo AwesomeSauce="Tummy"/>
Run Code Online (Sandbox Code Playgroud)

我得到错误

System.ArgumentException
'AwesomeSauce' property …
Run Code Online (Sandbox Code Playgroud)

wpf xaml wpf-controls

5
推荐指数
1
解决办法
3578
查看次数

标签 统计

wpf ×1

wpf-controls ×1

xaml ×1