title: Create a TextBoxSearch to filter from ListView WPF
body: <p>I'm creating a application that allows a user to add some Employee details into <code>EntityFramework</code> model using WPF.</p>
  
  <p>So far, I have a <code>ListView</code> to represent a list of employee names, and when you select the name of the employee, it selects that specific data in another <code>ListView</code>. I have accomplished this using a <code>Predicate</code> and a <code>ICollectionSource</code>.</p>
  
  <p>But what I want to achieve now, is to have a so called search engine. So when a user types in an employees name in a <code>TextBox</code> it filters the names of the employee names, depending on what is typed into the search box.</p>
  
  <p>I have used <a href="http://joshsmithonwpf.wordpress.com/2007/06/12/searching-for-items-in-a-listbox/" rel="noreferrer">This Link</a> as a guide, but I am not too sure how to implement it within my own design; in the example they have used a <code>Resource</code> and used an <code>Array</code>.</p>
  
  <p>This is what I have tried instead, using a <code>Predicate</code>;</p>
  
  <pre><code>    private EmployeeListViewModel()
          : base("")
      {
          EmployeeList = new ObservableCollection&lt;EmployeeViewModel&gt;(GetEmployees());
          this._view = new ListCollectionView(this.employeeList);
      }
  
      private ListCollectionView _view;
      public ICollectionView View
      {
           get { return this._view; }
      }
  
      private string _TextSearch;
      public string TextSearch
      {
          get { return _TextSearch; }
          set
          {
              _TextSearch = value;
              OnPropertyChanged("TextSearch");
  
              if (String.IsNullOrEmpty(value))
                  View.Filter = null;
              else
                  View.Filter = new Predicate&lt;object&gt;(o =&gt; ((EmployeeViewModel)o).FirstName == value);
          }
      }
  </code></pre>
  
  <p>in my view;</p>
  
  <pre><code>&lt;TextBox Height="23" Name="txtSearch" VerticalAlignment="Bottom" Margin="70,0,0,183" Width="100" Grid.Row="1"
            Text="{Binding TextSearch, UpdateSourceTrigger=PropertyChanged}"/&gt;
  </code></pre>
  
  <p>But what seems to happen is when I type something in, it throws this exception;</p>
  
  <p><code>Object reference not set to an instance of an object.</code></p>
  
  <p>So my question is, how can I implement this so it actually enables me to filter the list of names like in a searchbox? </p>
  
  <p>Any help would be grateful or guidance how to achieve this.</p>