public static int CheckTreeWalking(DependencyObject parent, bool checkForValidationErrors, bool leafFirst, bool logicalInsteadOfVisualTreeScan)
        {
            IEnumerator <DependencyObject> enumerator;

            enumerator = checkForValidationErrors
                ? GetElementsWithErrors(parent, true, leafFirst, logicalInsteadOfVisualTreeScan).GetEnumerator()
                : VisualLogicalTreeWalkHelper.GetElements(parent, true, leafFirst, logicalInsteadOfVisualTreeScan).GetEnumerator();

            enumerator.MoveNext(); // first

            int size = 0;

            foreach (DependencyObject obj in checkForValidationErrors
                ? GetElementsWithErrors(parent, false, leafFirst, logicalInsteadOfVisualTreeScan)
                : VisualLogicalTreeWalkHelper.GetElements(parent, false, leafFirst, logicalInsteadOfVisualTreeScan))
            {
                size++;

                Debug.Assert(ReferenceEquals(obj, enumerator.Current), "Tree element differs !");

                enumerator.MoveNext();
            }

            return(size);
        }
        private void ReportAllErrors()
        {
            if (m_DispatcherOperation != null)
            {
                return;
            }

            m_DispatcherOperation = Application.Current.Dispatcher.BeginInvoke(
                DispatcherPriority.DataBind,
                (Action) delegate()
            {
                foreach (Window w in Application.Current.Windows)
                {
                    IEnumerable <DependencyObject> enumeration = VisualLogicalTreeWalkHelper.GetElements(w, false, false, m_LogicalInsteadOfVisualTreeScan);
                    foreach (var element in enumeration)
                    {
                        checkErrors(element);
                    }
                }

                m_DispatcherOperation = null;
            });
        }