title: Making a WPF TextBox binding fire on each new character?
body: <p>How can I make a data binding update as soon as a new character is typed in a TextBox?</p>
  <p>I'm learning about bindings in WPF and now I've become stuck on a (hopefully) simple matter.</p>
  <p>I have a simple FileLister class where you can set a Path property, and then it will give you a listing of files when you access the FileNames property.
  Here is that class:</p>
  <pre class="lang-cs prettyprint-override"><code>class FileLister:INotifyPropertyChanged {
      private string _path = &quot;&quot;;
  
      public string Path {
          get {
              return _path;
          }
          set {
              if (_path.Equals(value)) return;
              _path = value;
              OnPropertyChanged(&quot;Path&quot;);
              OnPropertyChanged(&quot;FileNames&quot;);
          }
      }
  
      public List&lt;String&gt; FileNames {
          get {
              return getListing(Path);
          }
      }
  
      private List&lt;string&gt; getListing(string path) {
          DirectoryInfo dir = new DirectoryInfo(path);
          List&lt;string&gt; result = new List&lt;string&gt;();
          if (!dir.Exists) return result;
          foreach (FileInfo fi in dir.GetFiles()) {
              result.Add(fi.Name);
          }
          return result;
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
      protected void OnPropertyChanged(string property) {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null) {
              handler(this, new PropertyChangedEventArgs(property));
          }
      }
  }
  </code></pre>
  <p>I'm using the the FileLister as a StaticResource in this very simple app:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Window x:Class=&quot;WpfTest4.MainWindow&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:local=&quot;clr-namespace:WpfTest4&quot;
      Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
      &lt;Window.Resources&gt;
          &lt;local:FileLister x:Key=&quot;fileLister&quot; Path=&quot;d:\temp&quot; /&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;TextBox Text=&quot;{Binding Source={StaticResource fileLister}, Path=Path, Mode=TwoWay}&quot;
          Height=&quot;25&quot; Margin=&quot;12,12,12,0&quot; VerticalAlignment=&quot;Top&quot; /&gt;
          &lt;ListBox Margin=&quot;12,43,12,12&quot; Name=&quot;listBox1&quot; ItemsSource=&quot;{Binding Source={StaticResource ResourceKey=fileLister}, Path=FileNames}&quot;/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>The binding is working. If I change the value in the textbox and then click outside of it, the listbox contents will update (as long as the path exists).</p>
  <p>The problem is that I would like to update as soon as a new character is typed, and not wait until the textbox lose focus.</p>
  <p>How can I do that?
  Is there a way to do this directly in the xaml, or do I have to handle TextChanged or TextInput events on the box?</p>