//called recursively, searchIn doesn't have to be a UIElement because we will look at it's children for any child UIElemenets /// <summary> /// Recursively searches <c>searchIn</c> for the Query. /// </summary> /// <param name="searchIn">DependencyObject to search inside.</param> /// <param name="parentUIElementIsFindable">Whether the parent UI element has been determined as 'findable'. If the parent is findable then <c>searchIn</c> is finable too unless explicitly marked otherwise with IsFindable="false".</param> /// <returns>Whether searchIn or any of it's children where marked as either 'findable' or not (IsFindable="true" or IsFindable="false").</returns> protected bool FindText(DependencyObject searchIn, bool parentUIElementIsFindable) { bool foundIsFindableAttribute = false;//whether this element searchIn or its children were marked with isfindable bool searchChildren = parentUIElementIsFindable; if (searchIn == null) { return(foundIsFindableAttribute); } currentGlobalScanHighlightCount = 0; bool?isFindable = searchIn is UIElement?RapidFindReplaceControl.GetIsFindable(searchIn as UIElement) : true; if (searchIn is UIElement) { foundIsFindableAttribute = RapidFindReplaceControl.GetIsFindable(searchIn as UIElement) != null; } IRunReader runReader = null; if (searchIn is UIElement && WillSearchInElement(searchIn as UIElement, parentUIElementIsFindable, ref searchChildren, isFindable))//GetIsFindable is bool? - if null then just not set so use parentUIElementIsFindable { searchChildren = true; runReader = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn); } else if (!(searchIn is UIElement)) { runReader = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);//we might be able to get a runreader for non UIElement (eg RunCollectionRunReader) } if (runReader != null) { HighlightHandler handler = highlightHandlers.GetCreateHighlightHandler(searchIn, bodyHighlightAdornerBrush, bodyHighlightAdornerPen, bodyIterativeHighlightAdornerBrush, bodyIterativeHighlightAdornerPen); FindTextIn(runReader, handler.AddHighlight, Query); } //recurse through children if (searchIn is Visual || searchIn is System.Windows.Media.Media3D.Visual3D) { var childCount = VisualTreeHelper.GetChildrenCount(searchIn); for (var i = 0; i < childCount; ++i) { foundIsFindableAttribute |= FindText(VisualTreeHelper.GetChild(searchIn, i), searchChildren && isFindable != false); } } return(foundIsFindableAttribute); }
public DependencyObject LastKeyboardFocussedControl(RapidFindReplaceControlViewModel model) { //look for most recent UIElement that got focus that we will search (mostly this is to ignore menus and buttons that might have opened the find popup) foreach (WeakReference reference in focussedElementBuffer) { if (reference != null && reference.IsAlive) { UIElement targ = reference.Target as UIElement; bool dummy = true; if (model.WillSearchInElement(targ, true, ref dummy, RapidFindReplaceControl.GetIsFindable(targ))) { return(targ as DependencyObject); } } } return(null); }