private static void OnAutoCompleteItemsSource(object sender, DependencyPropertyChangedEventArgs e) { var tb = sender as TextBox; if (tb == null) return; //If we're being removed, remove the callbacks if (e.NewValue == null) { tb.TextChanged -= OnTextChanged; tb.KeyDown -= OnPreviewKeyDown; } else { //New source. Add the callbacks tb.TextChanged += OnTextChanged; tb.KeyDown += OnPreviewKeyDown; } }