具有 DependencyProperty 的用户控件在 MVVM Light 中
本文关键字:MVVM Light 控件 DependencyProperty 用户 具有 | 更新日期: 2023-09-27 18:31:57
我有一个用户控件,它为它添加了依赖属性。
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());
并在另一个用户控件中使用它
<local:FormatUserControl TextValue="{Binding Subject,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
当我使用它时,当我更改值时不为此属性设置值Subject
?
您的 FormatUserControl 是类,您应该为它注册属性,而不是像这样为 NumberFormatUserControl 注册属性(我不知道两个用户控件之间的关系是什么):
public static readonly DependencyProperty TextValueProperty = DependencyProperty.Register(
TextValuePropertyName,
typeof(string),
typeof(FormatUserControl),
new UIPropertyMetadata());