2

I am working on a (WPF + C#) application. I have to implement search functionality. It will allow to search all the occurrences of a particular string on the specific part of Window. What can be the best way to do this?

viky
  • 17,275
  • 13
  • 71
  • 90
  • Aren't you using a textbox to get the input? where actually is the string on which the search is to be made? – Amsakanna Jun 15 '10 at 11:32
  • Do you want to iterate over a set of controls and check their content for this a particular string? Content can be anything so hard to make general. Do you have a VM which you could search instead? – Wallstreet Programmer Jun 15 '10 at 13:11
  • @Veer: I am using TextBox, TextBlock, ComboBox, etc. to display strings and i need to search occurrence of particular string into them and highlight the occurrence. – viky Jun 17 '10 at 06:31
  • @Wallstreet Programmer: Yes, the same way. In my case Content I am searching will be string only. – viky Jun 17 '10 at 06:33

2 Answers2

2

Viky,

I hope I got you properly. You can take a look on what Kent Boogaart has: Search and Highlight Text in an Arbitrary Visual Tree:

alt text

Community
  • 1
  • 1
Anvaka
  • 15,658
  • 2
  • 47
  • 56
  • thanks for the reply its really helpful, but my window can contain other controls as well. like TextBox, ComboBox, i need to search Text in them also. Any suggestions? – viky Jun 16 '10 at 14:30
  • @Viky, as long as it's in the visual tree it should work (TextBoxes should work). As for the ComboBox... it's little trickier, because items in the drop down list are in popup's visual tree. In that case you would probably have to customize Kent's algorithm to check against "known" exceptions. – Anvaka Jun 16 '10 at 18:31
0

You should try using ICollectionView for filtering. Here is an example.

decyclone
  • 30,394
  • 6
  • 63
  • 80