我有一个为它添加DependencyProperty的UserControl。
public const string TextValuePropertyName = "TextValue";
public string TextValue
{
get
{
return (string)GetValue(TextValueProperty);
}
set
{
SetValue(TextValueProperty, value);
}
}
public static readonly DependencyProperty TextValueProperty = DependencyProperty.Register(
TextValuePropertyName,
typeof(string),
typeof(FormatUserControl),
new UIPropertyMetadata());
并在另一个Usercontrol中使用它
<local:FormatUserControl TextValue="{Binding Subject,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
当我使用此功能时,如果我更改Subject
值,请不要为此属性设置值?
答案 0 :(得分:1)
你的FormatUserControl是类,你应该为它注册属性而不是像这样的NumberFormatUserControl(我不知道两个用户控件之间的关系是什么):
public static readonly DependencyProperty TextValueProperty = DependencyProperty.Register(
TextValuePropertyName,
typeof(string),
typeof(FormatUserControl),
new UIPropertyMetadata());