title: WPF TextBox displayed value is not equal to TextBox.Text
body: <p>I check the postal code for about 60 countries. The user enters a postal code which is checked against the rules for that country. The US is an exception where I can auto-fill the value based on other street address information already entered. In some ways it's basically an auto-correction feature. The problem is the auto-filled value never re-displays if it matches the previous .Text value - the 'erroneous' zip code just entered by the user remains displayed!</p>
  
  <p>For example, field contains "12345", user deletes the "5", my property setter puts the value back to "12345", the binding getter returns "12345" (and at this point my _TextChanged event fires) but WPF still displays the user edited text "1234"!</p>
  
  <p>How do I force WPF to redisplay the value?</p>
  
  <p>To simplify the example I have hard-coded the ZipCode value (in the app it is computed in a separate method):</p>
  
  <pre><code>public String ZipCode
  {
      get { return _address.ZipCode; }
      set
      {
          _address.ZipCode = "12345";
          RaisePropertyChanged("ZipCode");
      }
  }
  </code></pre>
  
  <p>Here is the XAML:</p>
  
  <pre><code>&lt;TextBox Name="ZipBox" 
           Text="{Binding Path=ZipCode, UpdateSourceTrigger=PropertyChanged}"
           TextChanged="ZipBox_TextChanged" /&gt;
  </code></pre>
  
  <p>WPF knows the field changed cause it always fires this event. But none of those methods force WPF to correctly display "12345".</p>
  
  <pre><code>private void ZipBox_TextChanged(object sender, TextChangedEventArgs e)
  {
      ZipBox.InvalidateVisual();
      ZipBox.InvalidateMeasure();
      ZipBox.UpdateLayout();
  }
  </code></pre>
  
  <p>Edit: I also have created a custom static extension method .Refresh(this UIElement uiElement) which calls UIElement.Dispatcher.Invoke() and that also does not force the redraw.</p>