PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

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