//called recursively
        protected void FindText(DependencyObject searchIn, bool parentUIElementIsFindable)
        {
            if (searchIn == null)
            {
                return;
            }

            bool?isFindable = searchIn is UIElement?KFindBox.GetIsFindable(searchIn as UIElement) : true;

            IRunReader runReader = null;

            if (searchIn is UIElement && ((parentUIElementIsFindable && isFindable != false) || isFindable == true))//GetIsFindable is bool? - if null then just not set so use parentUIElementIsFindable
            {
                parentUIElementIsFindable = true;
                runReader = FindHandlerRegistry.CreateIRunReaderHandlerFor(searchIn);
            }

            if (runReader != null)
            {
                HighlightHandler handler = highlightHandlers.GetCreateHighlightHandler(searchIn as UIElement, bodyHighlightAdornerBrush, bodyHighlightAdornerPen);
                FindTextIn(runReader, handler.AddHighlight, searchText);
            }


            //recurse through children
            var childCount = VisualTreeHelper.GetChildrenCount(searchIn);

            for (var i = 0; i < childCount; ++i)
            {
                FindText(VisualTreeHelper.GetChild(searchIn, i), parentUIElementIsFindable);
            }
        }
Esempio n. 2
0
        //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);
        }