title: WPF TextBox EventTrigger sequence of events
body: <p>I have a dynamic WPF input form, whereby a list of input text boxes is displayed based on the contents of a collection of data. The text of each text box is bound to a Value field in the data, when any of these fields changes I am using firing a Command which then executes a calculation in a script (also dynamically provided) using the values of the input field.</p>
  
  <p>My question is how I can get the Command to execute after the field value has changed. At the moment I am firing the Command based on an event trigger using the TextChanged property. </p>
  
  <p>The issue is that the TextChanged property seems to fire before the value of the bound property is set. This means that although the command fires and executes the script, the field which is currently being editing will have the 'old' data in it still because of the sequence of events.</p>
  
  <p>The relevant bit of XAML code I am using is:</p>
  
  <pre><code>&lt;Label Visibility="{Binding HasInputFieldsSection, Converter={StaticResource visibilityConverter}}"&gt;Input parameters&lt;/Label&gt;
  
  &lt;ItemsControl Visibility="{Binding HasInputFieldsSection, Converter={StaticResource visibilityConverter}}"
                ItemsSource="{Binding Path=SelectedQualificationType.QualificationTypeInputFields.QualificationTypeFields}"&gt;
      &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel&gt;
                  &lt;Label Content="{Binding Label}" Visibility="{Binding Label, Converter={StaticResource stringVisibilityConverter}}"/&gt;
  
                  &lt;TextBox Text="{Binding Value, UpdateSourceTrigger=PropertyChanged, Delay=250}"&gt;
                      &lt;i:Interaction.Triggers&gt;
                          &lt;i:EventTrigger EventName="TextChanged"&gt;
                              &lt;cmd:EventToCommand Command="{Binding DataContext.ExecuteExpressionsCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}}" /&gt;
                          &lt;/i:EventTrigger&gt;
                      &lt;/i:Interaction.Triggers&gt;
                  &lt;/TextBox&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>I was hoping there would be a different event I could trigger the command on but after looking through the documentation for a WPF textbox and trying some alternative none of them seem appropriate.</p>
  
  <p>I could change the binding to be based on LostFocus rather than PropertyChanged but for a better user experience I would rather not. Likewise I could remove the delay on the input TextBox binding but ideally I would want this delay to remain, again for user experience.</p>
  
  <p>So in short the current sequence seems to be:</p>
  
  <ol>
  <li>user types something</li>
  <li>text changed gets fired</li>
  <li>command is fired</li>
  <li>bound field gets updated </li>
  </ol>
  
  <p>but I need it to be more like:</p>
  
  <ol>
  <li>user types something</li>
  <li>text changed gets fired</li>
  <li>bound field gets updated </li>
  <li>command is fired</li>
  </ol>
  
  <p>Is there a better event to fire off or way to accomplish what I am trying to do?</p>