1

i am programming in wpf.i have to scroll one page up when highlighted word move from viewportHeight.So i am using the below code.it works fine.

FrameworkContentElement fce = (textRange.Start.Parent as FrameworkContentElement);
            if (fce != null)
            {
                fce.BringIntoView();
            }

But after i need to use the below code for highlight word.

   TextRange fullRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
                fullRange.ClearAllProperties(); 
                TextPointer start = fullRange.Start.GetPositionAtOffset(offset);
                TextPointer end = start.GetPositionAtOffset(length);
                TextRange textRange = rtb.Selection;
                textRange.Select(start, end);
textRange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(m_DehighlightbackgroundColor));
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(m_DehighlightforegroundColor));

After i used fullRange.ClearAllProperties(); the fce.BringIntoView(); not working.I mean not scroll to highlighted word.

So,how to solve this issue?

Regards Arjun

arjun sanju
  • 135
  • 1
  • 1
  • 12

1 Answers1

2

This answer solved a similar issue for me:

How to bring Inline from a RichTextBox Child into View richtextbox-child-into-view

To summarise, try putting the following before BringIntoView:

Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { }));

Community
  • 1
  • 1
Joshua Mee
  • 582
  • 5
  • 20