title: Bind TextBox to Nullable Double?
body: <p>I am trying to bind a Double? to a TextBox, and I am having an issue, because when the user empties the textbox a validation happens.
  I thought my application had a validation in some place I couldn't find, so I created a quick app to test.</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          DataContext = new ViewModel() {Value = 3, Value2 = null};
      }
  }
  
  public class ViewModel
  {
      public double Value { get; set; }
      public double? Value2 { get; set; }
  }
  </code></pre>
  
  <p><strong>The xaml</strong></p>
  
  <pre><code>    &lt;StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5" Height="20px"&gt;
          &lt;TextBlock Margin="0,0,5,0"&gt;Double:&lt;/TextBlock&gt;
          &lt;TextBox Width="50px" Text="{Binding Value}"&gt;&lt;/TextBox&gt;
      &lt;/StackPanel&gt;
      &lt;StackPanel Grid.Row="1" Orientation="Horizontal" Margin="5" Height="20px"&gt;
          &lt;TextBlock Margin="0,0,5,0"&gt;Double?:&lt;/TextBlock&gt;
          &lt;TextBox Width="50px" Text="{Binding Value2}"&gt;&lt;/TextBox&gt;
      &lt;/StackPanel&gt;
  </code></pre>
  
  <p>When I run the application the TextBox bound to Value2, is empty, but if I type a value and then delete it, when the TextBox loses focus it shows an error. It only goes away when I type a value.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/5854860/set-null-to-property-in-mvvm-wpf-when-nothing-is-filled-in-textbox">this post</a> suggesting to use a string, but he was originally using a double and not <strong>double?</strong></p>
  
  <p>How can I make this work? Is the only way using a string? </p>
  
  <p>It seems odd to me that binding to <strong>double?</strong> wouldn't allow me setting null values.</p>