我有usercontrol。我想工作TextChange
TextBoxExtended.cs
public partial class TextBoxExtended : UserControl
{
public static readonly DependencyProperty MyTextPropertyProperty =
DependencyProperty.Register("MyTextProperty", typeof(string), typeof(TextBoxExtended), new UIPropertyMetadata(String.Empty));
public string MyTextProperty
{
get { return (string)GetValue(MyTextPropertyProperty); }
set { SetValue(MyTextPropertyProperty, value); }
}
TextBoxExtended.xaml
<local:TextBoxExtended x:Name="TextBoxSearch" Height="30" Margin="83,38,193,285" MyTextProperty="{Binding MyText, UpdateSourceTrigger=PropertyChanged}"/>
MainWindow.xaml
<local:TextBoxExtended x:Name="TextBoxSearch" Height="30" Margin="83,38,193,285" MyTextProperty="MyTextProperty"/>
视图模型
private string _myText;
public string MyText
{
get { return _myText; }
set
{
_myText = value;
RaisePropertyChanged();
}
}
public void RaisePropertyChanged()
{
MessageBox.Show(_myText);
}
更改文字时没有任何反应