How can I highlight, not select, text in a data bound WPF TextBox or RichTextBox? -


some context: i'm trying highlight occurrences of searched text in data bound textbox or richtextbox.

what have found until now: figured out how highlight text in richtextbox:

    <richtextbox>         <flowdocument>             <paragraph>                 <run>in this</run>                 <run background="yellow">example</run>                 <run>the word</run>                 <run background="yellow">example</run>                 <run>is highlighted.</run>             </paragraph>         </flowdocument>     </richtextbox> 

question: how can i, example, using ivalueconverter, bind richtextbox occurrences of expression "example" highlighted?

     string example = "example";      string exampledoc = "hello, example, hello example.";      flowdocument doc =         new flowdocument(new paragraph(new run("hello, example, hello example.")));      int pos = 0;      while (0 <= (pos = exampledoc.indexof(example)))      {         new bold(doc.contentstart.getpositionatoffset(pos),                  doc.contentstart.getpositionatoffset(pos + example.length));      } 

this started. easy put in valueconverter string flowdocument converterparameter of word want highlight. watch out textpointer changing add more formats, you'll see highlighting shift left. i'm sure you'll figure out best way handle in situation.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -