public void ForEachElementInTree_DepthFirst(IUIElementAction action) { Stack <UIElement> searchStack = new Stack <UIElement>(); IList <UIElement> elementList = new List <UIElement>(); searchStack.Push(this); while (searchStack.Count > 0) { UIElement current = searchStack.Pop(); action.Equals(current); elementList.Clear(); current.AddChildren(elementList); foreach (UIElement child in elementList) { searchStack.Push(child); } } }
public UIElement FindElement_DepthFirst(IMatcher matcher) { Stack <UIElement> searchStack = new Stack <UIElement>(); IList <UIElement> elementList = new List <UIElement>(); searchStack.Push(this); while (searchStack.Count > 0) { UIElement current = searchStack.Pop(); if (matcher.Match(current)) { return(current); } elementList.Clear(); current.AddChildren(elementList); foreach (UIElement child in elementList) { searchStack.Push(child); } } return(null); }