Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: DateTimePicker - enter date as numbers only

$
0
0
Hi,

The idea is to change the "Text" value. Here's a start :
<local:MyDateTimePicker Format="ShortDate" />
public class MyDateTimePicker : DateTimePicker
  {
    private bool _isChangingText = false;
    protected override void OnTextChanged( string previousValue, string currentValue )
    {
      if( !_isChangingText && (currentValue.Count() == 8) )
      {
        var cultureInfo = Thread.CurrentThread.CurrentCulture;
        var newValue = currentValue.Insert( 4, cultureInfo.DateTimeFormat.DateSeparator );
        newValue = newValue.Insert( 7, cultureInfo.DateTimeFormat.DateSeparator );
        _isChangingText = true;
        this.Text = newValue;
        _isChangingText = false;
        return;
      }

      base.OnTextChanged( previousValue, currentValue );
    }
  }

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>