Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The sad news is that the textbox of the DatePicker is set to update its binding source <em>only</em> when it loses focus. The good-ish news is that you can hook into the process via the <code>DatePicker</code>'s <code>ControlTemplate</code>:</p> <p><strong>The XAML:</strong></p> <pre><code>&lt;DatePicker SelectedDate="{Binding DateVal}" x:Name="__picker" /&gt; </code></pre> <p><strong>And the Code Behind:</strong></p> <pre><code>DateTime? _dateVal = DateTime.Today; public Nullable&lt;DateTime&gt; DateVal { get { return _dateVal; } set { if (_dateVal == value) return; _dateVal = value; OnPropertyChanged("DateVal"); } } private void Window_Loaded(object sender, RoutedEventArgs e) { DatePickerTextBox pickerTextBox = __picker.Template.FindName("PART_TextBox", __picker) as DatePickerTextBox; if (pickerTextBox == null) return; pickerTextBox.TextChanged += new TextChangedEventHandler(pickerTextBox_TextChanged); } void pickerTextBox_TextChanged(object sender, TextChangedEventArgs e) { DatePickerTextBox tb = sender as DatePickerTextBox; if (tb == null) return; if (string.IsNullOrEmpty(tb.Text)) { __picker.SelectedDate = null; } } </code></pre> <p>I just fiddled around with it and my guess is that the reason you don't get more frequent updates is the circular relation between the text and selected date properties. Making sure that we get updates for null DateTimes should be OK though.</p> <p><strong>EDIT</strong></p> <p>Updated the event handler to update the pickers <code>SelectedDate</code> property rather than the property in the view model. This way you can keep the hack entirely within the view while remaining viewmodel agnostic.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload