public static IEnumerable <T> GetVisualDescendents <T>(this FrameworkElement root, bool allAtSameLevel) where T : FrameworkElement
        {
            bool found = false;

            foreach (FrameworkElement frameworkElement in ExtensionMethods.GetVisualDescendents(root))
            {
                if (frameworkElement is T)
                {
                    found = true;
                    yield return(frameworkElement as T);
                }
                else if (found && allAtSameLevel)
                {
                    break;
                }
            }
        }
        public static FrameworkElement FindVisualChild(this FrameworkElement root, string name)
        {
            FrameworkElement frameworkElement1 = root.FindName(name) as FrameworkElement;

            if (frameworkElement1 != null)
            {
                return(frameworkElement1);
            }
            foreach (FrameworkElement frameworkElement2 in ExtensionMethods.GetVisualDescendents(root))
            {
                FrameworkElement frameworkElement3 = frameworkElement2.FindName(name) as FrameworkElement;
                if (frameworkElement3 != null)
                {
                    return(frameworkElement3);
                }
            }
            return((FrameworkElement)null);
        }