public static T FindGridElement <T>(DependencyObject obj, bool failIfNothingFound = true) where T : DependencyObject { ObjectChecker <T> checker = new ObjectChecker <T>(); DObjectChecker.CheckSubTree(obj, checker, failIfNothingFound); return((T)checker.Element); }
public static void CheckSubTree(DependencyObject dObject, DObjectChecker checker, bool failIfNothingFound) { VisualTreeEnumerator visualTreeEnumerator = new VisualTreeEnumerator(dObject); DependencyObjectCheckerEnumerator dObjectCheckerEnumerator = new DependencyObjectCheckerEnumerator(checker); dObjectCheckerEnumerator.MoveNext(); while (visualTreeEnumerator.MoveNext()) { if (dObjectCheckerEnumerator.Current.CheckElement(visualTreeEnumerator.Current, visualTreeEnumerator.Level)) { DObjectChecker parent = (DObjectChecker)dObjectCheckerEnumerator.CurrentParent; if (parent != null) { Assert.IsTrue(IsParent(dObjectCheckerEnumerator.Current.Element, parent.Element)); } if (!dObjectCheckerEnumerator.MoveNext()) { checker.CheckLevels(); return; } } } if (failIfNothingFound) { Assert.Fail("Element not found: " + dObjectCheckerEnumerator.Current); } }
public static void CheckNoSubTree(DependencyObject dObject, DObjectChecker checker) { try { CheckSubTree(dObject, checker); } catch { return; } Assert.Fail(); }
public static T FindGridElement <T>(DependencyObject obj, DependencyProperty property, object value, bool exactType = false, bool onlyVisibleChildren = false, bool failIfNothingFound = true) where T : DependencyObject { ObjectChecker <T> checker = new ObjectChecker <T>(new DPropertyInfo(property, value), exactType, onlyVisibleChildren); DObjectChecker.CheckSubTree(obj, checker, failIfNothingFound); return((T)checker.Element); }
public static void CheckSubTree(DependencyObject dObject, DObjectChecker checker) { CheckSubTree(dObject, checker, true); }
public DependencyObjectCheckerEnumerator(DObjectChecker checker) : base(checker) { }
public DObjectChecker(Type dObjectType, DObjectChecker child) : this(dObjectType, new DObjectChecker[] { child }) { }