/// <summary>
        /// Handles a change to the undo manager for a given dependency object.
        /// </summary>
        /// <param name="dependencyObject">The target object for this attached property.</param>
        /// <param name="dependencyPropertyChangedEventArgs">The event parameters.</param>
        private static void OnUndoManagerChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            // This will remove the previous UndoManager from the object.  Note that an old UndoManager must be removed from the class before a new one can be
            // added, otherwise the events will still be connected to the old manager after the new one is set.
            if (dependencyPropertyChangedEventArgs.OldValue is UndoManager)
            {
                // This is the 'UnDo' manager for the old scope.
                UndoManager undoManager = dependencyPropertyChangedEventArgs.OldValue as UndoManager;

                // There is also a specific handler for the particulars of a given class (TextBox, CheckBox, etc.).  To save time, a mapping is used to find an
                // interface to the methods that handle the particulars of each class.  An entry must be made in this map for any new user interface elements
                // not covered by default by this class.
                IUndo iUndo;
                if (undoManager.TypeUndoMap.TryGetValue(dependencyObject.GetType(), out iUndo))
                {
                    iUndo.Unregister(dependencyObject);
                }
            }

            // This will connect a User Interface Element to an UndoManager.  The UndoManager will be hooked into the elements events and when the control's
            // content is changed, entries will be made in a stack that keeps track of the operations.  This stack is integrated with all the other elements in
            // the scope of this UndoManager so that actions are 'Undone' in the order they were added to the UndoManager in this scope.
            if (dependencyPropertyChangedEventArgs.NewValue is UndoManager)
            {
                // This is the 'UnDo' manager for the new scope.
                UndoManager undoManager = dependencyPropertyChangedEventArgs.NewValue as UndoManager;

                // There is also a specific handler for the particulars of a given class (TextBox, CheckBox, etc.).  To save time, a mapping is used to find an
                // interface to the methods that handle the particulars of each class.  An entry must be made in this map for any new user interface elements
                // not covered by default by this class.
                IUndo iUndo;
                if (undoManager.TypeUndoMap.TryGetValue(dependencyObject.GetType(), out iUndo))
                {
                    iUndo.Register(dependencyObject);
                }
            }
        }
Exemple #2
0
 public UndoBase(UndoManager undoManager)
 {
     // Initialize the object.
     this.undoManager = undoManager;
 }
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public ToggleButtonUndo(UndoManager undoManager)
     : base(undoManager)
 {
     // Initialzie the object
     this.isUndoing = false;
 }
 /// <summary>
 /// Set accessor for the UndoScope attached property.
 /// </summary>
 /// <param name="dependencyObject">The target object for this attached property.</param>
 /// <param name="undoManager">The value for the attached property.</param>
 public static void SetUndoScope(DependencyObject dependencyObject, UndoManager undoManager)
 {
     // This method shouldn't do anything more than set the attached property as XAML bypasses this accessor.
     dependencyObject.SetValue(UndoScopeProperty, undoManager);
 }
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public RichTextBoxUndo(UndoManager undoManager) : base(undoManager)
 {
 }
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public TextBoxBaseUndo(UndoManager undoManager) : base(undoManager)
 {
 }
Exemple #7
0
 /// <summary>
 /// Creates an object that manages the Undo/Redo logic that is particular to this control.
 /// </summary>
 /// <param name="undoManager">An object that coordinates all the undo/redo actions in a scope.</param>
 public SelectorUndo(UndoManager undoManager) : base(undoManager)
 {
     // Initialzie the object
     this.isUndoing = false;
 }