title: Wpf textbox converter to double in combination with updatesourcetrigger=propertychanged
body: <p>In our project we have a WPF textbox that is bound to a double. There is a converter that allows in the convertback to for example use both "." and "," to as decimal points and in the convert method it formats the double to the n2 numeric format. 
    Here you can see a simplefied version of  our converter:</p>
  
  <pre><code>public class DoubleConverter:IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (value == null || value.GetType() != typeof(double))
              return null;
          else
              return ((double)value).ToString("n2");
      }
  
  
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          if (value == null)
             return null
          else
               return Double.Parse(((string)value).Replace('.',','));
      }
  }
  </code></pre>
  
  <p>The textbox looks like this:</p>
  
  <pre><code>        &lt;TextBox  Text="{Binding Path=Factor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Width="500" Height="50" /&gt;
  </code></pre>
  
  <p>And the double property raises a propertychanged event:</p>
  
  <pre><code>public double Factor
      {
          get { return _factor; }
          set
          {
              _factor = value;
              if (PropertyChanged != null)
                  PropertyChanged(this, new PropertyChangedEventArgs("Factor"));
          }
      }
  </code></pre>
  
  <p>This used to work fine in previous versions of WPF because the convert was'nt called when you were entering text. This behavior apparently has changed and now the convert method is called on every text entry, causing the double to be formatted when you type something.Even if you don't use formatting you have the problem of not being able to enter a decimal point.</p>
  
  <p>This can be solve by not using UpdateSourceTrigger=Propertychanged, but we need this for validation. We implement validation by using the IDataErrorInterface. I know there is a <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.bindingexpressionbase.validatewithoutupdate%28v=vs.100%29.aspx" rel="nofollow">ValidateWithoutUpdate method</a>, but this doesn't work for validation using the IDataErrorInterface.</p>
  
  <p>So what I basicly need is ConvertBack (and thus the validation) to happen OnPropertyChanged and the Convert to only happen OnLostFocus.<br>
    Is this possible? Or is there another solution for our problem?</p>