我想创建一个简单的搜索框,因此我有一个文本框,当有人输入搜索词时,我想执行搜索方法。
问题在于,当我从文本框中点击出来时,onChange方法会执行,而我希望在我输入时执行onChange事件。
<TextBox Text="{Binding SearchTerm}" />
public static readonly DependencyProperty SearchTermProperty =
DependencyProperty.Register("SearchTerm", typeof(string), typeof(MainWindow), new PropertyMetadata(string.Empty, OnCaptionPropertyChanged));
private static void OnCaptionPropertyChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs e)
{
((MainWindow)dependencyObject).SearchTracks(e.NewValue.ToString());
}
谢谢!