I'm looking for a WPF textarea component that would allow the user to search inside it. Something similar to the notepad, but as a reusable component.
A:
You can use a normal TextBox for this unless you want extra features notepad doesn't have.
Use int startIndex = textBox.Text.IndexOf(searchString)
to determine where the searchstring is located and textBox.Select(startIndex, searchString.Length)
to select the text.
When you want to search for the next item keep track of the startIndex and use startIndex = textBox.Text.IndexOf(searchString, startIndex + searchString.Length)
and use the select again.
Btw this works the same for the RichTextBox.
Edit: For a "multiline" textbox use: <TextBox AcceptsReturn="True" .../>
Zenuka
2009-09-02 08:42:28
There's much moer needed from searchable textarea than IndexOf. What about the search form itself? What about indicating how many results found? Of course I can implement it myself, but it's much better to use an existing reusable component.
Elazar Leibovich
2009-09-02 09:42:26
You said you where looking for "a WPF textarea component that would allow you to search inside".... Not that you wanted a complete notepad "search window". Anyway you can use the link you posted, I don't know any other components...
Zenuka
2009-09-02 13:00:32
A:
Not exactly available as component, but MSDN has example code for notepad application with search capability in WPF. I guess I can modify the code for my needs.
Elazar Leibovich
2009-09-02 09:51:43