//------------------------------------------------------
        //
        //  Privte Methods
        //
        //------------------------------------------------------

        #region Private Methods
        
        // Private helper that adds a new UIElementPropertyUndoUnit to the undo stack.
        private static void AddPrivate(ITextContainer textContainer, UIElement uiElement, DependencyProperty property, object newValue)
        {
            UndoManager undoManager = TextTreeUndo.GetOrClearUndoManager(textContainer);

            if (undoManager == null)
            {
                return;
            }

            object currentValue = uiElement.ReadLocalValue(property);

            if (currentValue is Expression)
            {
                // Can't undo when old value is an expression, so clear the stack.
                if (undoManager.IsEnabled)
                {
                    undoManager.Clear();
                }
                return;
            }

            if (currentValue.Equals(newValue))
            {
                // No property change.
                return;
            }

            undoManager.Add(new UIElementPropertyUndoUnit(uiElement, property, currentValue));
        }