none
wpf richtextbox find string and if found scroll to it. RRS feed

  • Question

  •  

    I have a richTextBox in wpf.

    Within the rich text I have a string "xxx" that's just behond the visible text.

    I want to programmatically search for the text and if found, scroll the content of the richTextBox so that the found text is visible.

     

    The following code appears to find the string contained within the myGoTo variable

     

    FlowDocument doc = richTextBox1.Document;

    TextPointer cur = doc.ContentStart;

    TextPointer myPosition = FindWordFromPosition(cur, myGoTo);

    if (myPosition != null)

    {

     

    but I am unable to make the content scroll to the position found

     

    I have tries a scrollViewer but it requires an int for the y coordinate - I don't know how to find this from the myPostition TextPointer

     

    Help, help, help

     

    Regards,

     

    Dave.

    Thursday, May 8, 2008 3:20 PM

Answers

All replies

  • Help, Help, Help

     

    I have a richTextBox in wpf.

    Within the rich text I have a string "xxx" that's just beyond the visible text.

    I want to programmatically search for the text and if found, scroll the content of the richTextBox so that the found text is visible.

     

    The following code appears to find the string contained within the myGoTo variable

     

    FlowDocument doc = richTextBox1.Document;

    TextPointer cur = doc.ContentStart;

    TextPointer myPosition = FindWordFromPosition(cur, myGoTo);

    if (myPosition != null)

    {

     

    but I am unable to make the content scroll to the position found

     

    I have tried a scrollViewer but it requires an int for the y coordinate - I don't know how to find this from the myPostition TextPointer

     

    Help, help, help

     

    Regards,

     

    Dave.

    Friday, May 9, 2008 1:44 PM
  • try selecting text.. that should bring it in focus

     

    Saturday, May 10, 2008 4:16 AM
    Moderator
  • You can refer to my blog post for answer:
    http://shevaspace.blogspot.com/2007/11/how-to-search-text-in-wpf-flowdocument.html

    Hope that helps
    Monday, May 12, 2008 4:40 AM
  • you could try performing a selection. this would bring it in focus

    Monday, May 12, 2008 5:01 AM
    Moderator