public static IEnumerable <FrameworkElement> GetVisualAncestors(this FrameworkElement node)
 {
     for (FrameworkElement parent = ExtensionMethods.GetVisualParent(node); parent != null; parent = ExtensionMethods.GetVisualParent(parent))
     {
         yield return(parent);
     }
 }
        private static void GetAncestorVisualTree(this FrameworkElement node, List <string> children)
        {
            string str = (string.IsNullOrEmpty(node.Name) ? "[Anon]" : node.Name) + ": " + node.GetType().Name;

            children.Insert(0, str);
            FrameworkElement visualParent = ExtensionMethods.GetVisualParent(node);

            if (visualParent == null)
            {
                return;
            }
            ExtensionMethods.GetAncestorVisualTree(visualParent, children);
        }