public static object FindRecursive(this FrameworkElement element, Type type) { while (element != null) { element = element.GetParentVisual(); if ((element != null) && type.IsAssignableFrom(element.GetType())) { return element; } } return null; }