private static TextPointer Highlight(FlowDocument document, Interval interval)
        {
            if (document == null)
                throw new ArgumentNullException("document");

            TextPointer contentStart = document.ContentStart;

            // clear any existing highlight
            TextRange documentRange = new TextRange(document.ContentStart, document.ContentEnd);
            documentRange.ApplyPropertyValue(FlowDocument.BackgroundProperty, FlowDocument.BackgroundProperty.DefaultMetadata.DefaultValue);

            if (interval == null)
                return null;

            // highlight the new text
            int startOffset = interval.Start;
            int endOffset = interval.End;
            TextPointer highlightStart = document.GetPointerFromCharOffset(ref startOffset);
            TextPointer highlightStop = document.GetPointerFromCharOffset(ref endOffset);
            if (startOffset != 0 || endOffset != 0)
                return null;

            var textRange = new TextRange(highlightStart, highlightStop);
            textRange.ApplyPropertyValue(FlowDocument.BackgroundProperty, Brushes.Yellow);
            return textRange.Start;
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether the specified interval falls completely within this interval.
        /// </summary>
        /// <param name="interval">The interval to check.</param>
        /// <returns>true if the specified interval falls completely within this interval, otherwise false.</returns>
        public bool Contains(Interval interval)
        {
            if (interval == null)
                throw new ArgumentNullException("interval");

            return interval.Start >= this.Start && interval.End <= this.End;
        }