我创建了两个完全相同的自定义控件,只是它们属于两种不同的类型。
控制一
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)