/// <summary>
        /// Enqueues any elements within the specified tree that have invalid measure, arrange, or styles, but
        /// were previously removed from the queues as a result of being orphaned by a destroyed window.
        /// </summary>
        /// <param name="root">The root of the tree to restore.</param>
        internal void RestoreToQueues(DependencyObject root)
        {
            Contract.Require(root, nameof(root));

            if (root is UIElement uiElement)
            {
                if (!uiElement.IsMeasureValid)
                {
                    MeasureQueue.Enqueue(uiElement);
                }

                if (!uiElement.IsArrangeValid)
                {
                    ArrangeQueue.Enqueue(uiElement);
                }

                if (!uiElement.IsStyleValid)
                {
                    StyleQueue.Enqueue(uiElement);
                }
            }

            VisualTreeHelper.ForEachChild(root, this, (child, state) =>
            {
                ((PresentationFoundation)state).RestoreToQueues(child);
            });
        }