private static void RemoveEventHandlers(TextBoxBase textBox, UndoManager manager) { if (textBox != null && manager != null) { textBox.RemoveHandler(CommandManager.PreviewExecutedEvent, new ExecutedRoutedEventHandler(manager.ExecutedHandler)); textBox.TextChanged -= new TextChangedEventHandler(manager.TextChangedHandler); } }
/// <summary> /// Removes this object from the chain of events that notify listeners of changes to the content. /// </summary> /// <param name="dependencyObject">The target element that will no longer be registered for state change events.</param> public override void Unregister(DependencyObject dependencyObject) { // This will remove this object from the chain of events that keep the control integrated with the Undo/Redo operations // in a scope. TextBoxBase textBox = dependencyObject as TextBoxBase; textBox.RemoveHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(TextChangedHandler)); }