我有一个自定义文本框,如下所示:
public class CustomTextBox : TextBox
{
public static DependencyProperty CustomTextProperty =
DependencyProperty.Register("CustomText", typeof(string),
typeof(CustomTextBox));
static CustomTextBox()
{
TextProperty.OverrideMetadata(typeof(SMSTextBox),
new FrameworkPropertyMetadata(string.Empty,
FrameworkPropertyMetadataOptions.Journal |
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(CustomTextBox_OnTextPropertyChanged));
}
public string CustomText
{
get { return (string)GetValue(CustomTextProperty); }
set { SetValue(CustomTextProperty, value); }
}
private static void CustomTextBox_OnTextPropertyChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
CustomTextBox customTextBox = d as CustomTextBox;
customTextBox.SetValue(CustomTextProperty, e.NewValue);
}
}
我正在将XAML中的自定义文本属性绑定 -
<local:CustomTextBox CustomText="{Binding ViewModelProperty}" />
我遇到的问题是,当我在CustomTextBox中输入任何内容时,ViewModelProperty没有更新,即ViewModelProperty没有得到更新。CustomTextProperty正在更新,但我想我需要做一些额外的工作使绑定也起作用。
我该怎么做?对此提供任何帮助都将不胜感激。
谢谢。