PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/BookReader/BookReader/Reader/Common/SearchFilter.cs

#
C# | 37 lines | 31 code | 6 blank | 0 comment | 3 complexity | 72a9ca45216e0de10ebbfa649d302fe2 MD5 | raw file
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows.Controls;
  4. namespace BookReader.Reader.Common
  5. {
  6. public class SearchFilter
  7. {
  8. public SearchFilter( ICollectionView filteredView, TextBox textBox )
  9. {
  10. string filterText = "";
  11. filteredView.Filter = delegate( object obj )
  12. {
  13. if( String.IsNullOrEmpty( filterText ) )
  14. return true;
  15. IBook bk = obj as IBook;
  16. if( bk == null )
  17. return false;
  18. int index = bk.FileName.IndexOf(
  19. filterText,
  20. 0,
  21. StringComparison.InvariantCultureIgnoreCase );
  22. return index > -1;
  23. };
  24. textBox.TextChanged += delegate
  25. {
  26. filterText = textBox.Text;
  27. filteredView.Refresh();
  28. };
  29. }
  30. }
  31. }