Reputation: 33643
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.
Upvotes: 1
Views: 2873
Reputation: 33643
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.
Upvotes: 0
Reputation: 3250
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" .../>
Upvotes: 2