title: Problems setting WPF Datepicker to Null
body: <p>I'm using WPF and MVVM.  I have a property in my model that is a nullable Datetime (Datime?).</p>
  
  <p>My Xaml looks like:</p>
  
  <pre><code>&lt;CheckBox Grid.Row="0" Grid.Column="2" x:Name="ChkBoxFromDate"
            Margin="10,0,0,5" FontWeight="Bold"&gt;
      Orders with Trades After Date:
  &lt;/CheckBox&gt;
  &lt;DatePicker Grid.Row="1" Grid.Column="2" Margin="10,0,0,0"
              SelectedDate="{Binding FromDate}" HorizontalContentAlignment="Stretch"&gt;
      &lt;DatePicker.Style&gt;
          &lt;Style TargetType="{x:Type DatePicker}"&gt;
              &lt;Setter Property="SelectedDate" Value="{Binding Path=FromDate, Mode=TwoWay}" /&gt;
              &lt;Style.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding ElementName=ChkBoxFromDate, Path=IsChecked}" Value="false"&gt;
                      &lt;Setter Property="SelectedDate" Value="{x:Null}" /&gt;
                      &lt;Setter Property="IsEnabled" Value="false" /&gt;
                  &lt;/DataTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/DatePicker.Style&gt;
  &lt;/DatePicker&gt;
  </code></pre>
  
  <p>I have the same pattern of disabling and clearing via checkbox on a textbox and cobmobox and it works just fine.  With Datepicker, the setting of the Null for selecteddate does not work.  Neither the UI nor the model gets updated.  IsEnabled gets set and the control greys out, but the value in the datepicker remains.  What am I missing?</p>
  
  <p><strong>Update</strong></p>
  
  <p>So apparently this is a deeper issue than I initially thought.  What I thought was working on the textbox and combobox was not if fact working (the UI only made it look that way).  What happens with the above code is that you are in fact clearing the binding by setting it to Null.  I was hoping that it would be setting the value of the binding, but this is not the case.  When you use the setter you are in fact clearing the binding and setting the property to null which is why the model does not get updated.  So why does the code below work and why did the textbox and combobox 'appear' to clear themselves and the datepicker does not.  As far as I can tell, the datepicker 'textbox' is not directly connected to the SelectedDate property.  This is how it can display "Select a date" when it's null or empty and display a date otherwise.  In other words there is some magic happening between setting the SelectedDate and displaying the text in the textbox.  This is what allows the 'hack' to work in the xaml below.  By setting the text (instead of SelectedDate) I am not clearing the binding on SelectedDate, but rather exercising the magic that the Control does to synchronize the Text property with the SelectedDate property.  You can do the same trick for Combobox.  For textbox however, the property you want to bind IS the text property and there does not appear to be a way to get around this.  My work around for this control ended up being adding a command to the checkbox which sets the textbox binding value to null from the Model end of things and a binding to the IsChecked property.  If anyone has any better ideas, please post below.</p>