public static DependencyObject GetFirstElementWithErrors(DependencyObject parent, bool nonRecursiveTreeParsingAlgorithm, bool leafFirst, bool logicalInsteadOfVisualTreeScan)
        {
            if (leafFirst)
            {
                if (nonRecursiveTreeParsingAlgorithm)
                {
                    foreach (
                        DependencyObject errorObj in
                        FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkLeafFirst_NonRecursive(parent, logicalInsteadOfVisualTreeScan))
                        )
                    {
                        return(errorObj);
                    }
                }
                else
                {
                    foreach (
                        DependencyObject errorObj in
                        FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkLeafFirst_Recursive(parent, logicalInsteadOfVisualTreeScan)))
                    {
                        return(errorObj);
                    }
                }
            }
            else
            {
                if (nonRecursiveTreeParsingAlgorithm)
                {
                    foreach (
                        DependencyObject errorObj in
                        FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkDepthFirst_NonRecursive(parent, logicalInsteadOfVisualTreeScan))
                        )
                    {
                        return(errorObj);
                    }
                }
                else
                {
                    foreach (
                        DependencyObject errorObj in
                        FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkDepthFirst_Recursive(parent, logicalInsteadOfVisualTreeScan)))
                    {
                        return(errorObj);
                    }
                }
            }

            return(null);
        }
        public static IEnumerable <DependencyObject> GetElementsWithErrors(DependencyObject parent, bool nonRecursiveTreeParsingAlgorithm, bool leafFirst, bool logicalInsteadOfVisualTreeScan)
        {
            if (leafFirst)
            {
                if (nonRecursiveTreeParsingAlgorithm)
                {
                    return(FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkLeafFirst_NonRecursive(parent, logicalInsteadOfVisualTreeScan)));
                }

                return(FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkLeafFirst_Recursive(parent, logicalInsteadOfVisualTreeScan)));
            }

            if (nonRecursiveTreeParsingAlgorithm)
            {
                return(FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkDepthFirst_NonRecursive(parent, logicalInsteadOfVisualTreeScan)));
            }

            return(FilterElementsWithErrors(VisualLogicalTreeWalkHelper.WalkDepthFirst_Recursive(parent, logicalInsteadOfVisualTreeScan)));
        }