public static TType GetAncestorOfType <TType>(this FrameworkElement thisObject) { TType type = default(TType); foreach (object obj in VisualTreeExtensions.GetVisualAncestors((DependencyObject)thisObject)) { if (obj is TType || typeof(TType).IsAssignableFrom(obj.GetType())) { type = (TType)obj; break; } } return(type); }
protected override void OnClick() { var ancestor = VisualTreeExtensions .GetVisualAncestors(Parent) .OfType <LoadingContentControl>() .FirstOrDefault(); if (ancestor != null) { var lri = ancestor.LoadingRetryInstance; if (lri == null) { throw new InvalidOperationException("No associated data context that implements ILoadingRetryInstance."); } lri.RetryLoad(); } else { throw new InvalidOperationException("No visual parent is of type LoadingContentControl."); } base.OnClick(); }
public static Rect TranslateToParent(this Rect rect, FrameworkElement child, FrameworkElement parent) { foreach (FrameworkElement element in Enumerable.OfType <FrameworkElement>((IEnumerable)VisualTreeExtensions.GetVisualAncestors((DependencyObject)child))) { if (element != parent) { Rect layoutSlot = LayoutInformation.GetLayoutSlot(element); rect = RectExtensions.Translate(rect, layoutSlot.X, layoutSlot.Y); } else { break; } } return(rect); }