public static DependencyObject FindAncestorByType(DependencyObject element, Type type, bool specificTypeOnly) { if (element == null) { return(null); } if (specificTypeOnly ? (element.GetType() == type) : (element.GetType() == type) || (element.GetType().IsSubclassOf(type))) { return(element); } return(VisualTreeHelperEx.FindAncestorByType(VisualTreeHelper.GetParent(element), type, specificTypeOnly)); }
public static T FindAncestorByType <T>(DependencyObject depObj) where T : DependencyObject { if (depObj == null) { return(default(T)); } if (depObj is T) { return(( T )depObj); } T parent = default(T); parent = VisualTreeHelperEx.FindAncestorByType <T>(VisualTreeHelper.GetParent(depObj)); return(parent); }
private static GraphAreaBase GetAreaFromObject(object obj) { GraphAreaBase area = null; if (obj is VertexControl) { area = ((VertexControl)obj).RootArea; } else if (obj is EdgeControl) { area = ((EdgeControl)obj).RootArea; } else if (obj is DependencyObject) { area = VisualTreeHelperEx.FindAncestorByType((DependencyObject)obj, typeof(GraphAreaBase), false) as GraphAreaBase; } return(area); }