title: Intercept Silverlight DatePicker's convert from text to DateTime
body: <p>I want <code>DatePicker</code> to convert the following text pieces to <code>DateTime</code> (shown in international format) so my customers can write a date in <code>DatePicker</code> textbox faster so it is not just <code>DateTime.Parse</code> I will use:</p>
  
  <pre><code>"3" to 2009-10-03
  "14" to 2009-10-14
  "1403" to 2009-03-14
  "140310" to 2010-03-14
  "14032010" to 2010-03-14
  </code></pre>
  
  <p>I have tried different methods to do it but they do not work. I have tried to bind <code>DatePicker.Text</code>/<code>DatePicker.SelectedDate</code>/<code>DatePicker.DisplayDate</code> with a custom valueconverter. But it do not work because <code>DatePicker</code> already have processed the text before I get to the text.</p>
  
  <p>I have also tried to convert in the <code>DatePicker</code> <code>TextBox.LostFocus</code> like this:</p>
  
  <pre><code>public class CustomDatePicker : DatePicker
  {
      private DatePickerTextBox textBox;
  
      public override void OnApplyTemplate()
      {
          base.OnApplyTemplate();
  
          textBox = this.GetTemplateChild("TextBox") as DatePickerTextBox;
  
          if (textBox != null)
              textBox.LostFocus += textBox_LostFocus;
      }
  
      void textBox_LostFocus(object sender, RoutedEventArgs e)
      {
          if (textBox == null) return;
  
          DateTime result;
  
          // This is my method for converting my special cases, 
          // parses d, dd, mm, ddmm, ddmmyy, ddmmyyyy
          if (textBox.Text.TryParseShortcut(out result)) 
          {
              // I have also tried with 
              // this.SelectedDate/DisplayDate = result;
              textBox.Text = result.ToString("dd/MM/yyyy"); 
              return;
          }
  
          if (DateTime.TryParse(textBox.Text, out result))
          {
              // I have also tried with 
              // this.SelectedDate/DisplayDate = result;
              textBox.Text = result.ToString("dd/MM/yyyy");
              return; 
          }
      }
  }
  </code></pre>
  
  <p>Any ideas?</p>