diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeParser.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeParser.cs index 14539718..32cafefa 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeParser.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeParser.cs @@ -105,11 +105,14 @@ namespace Microsoft.Windows.Controls var dates = date.Split(dateSeparators, StringSplitOptions.RemoveEmptyEntries).ToList(); var formats = Format.Split(dateSeparators, StringSplitOptions.RemoveEmptyEntries).ToList(); + if (dates.Count != formats.Count) + return string.Empty; + //strip out the date pieces for (int i = 0; i < formats.Count; i++) { var format = formats[i]; - if (!format.Equals("dddd") && !format.Contains(DateTimeFormatInfo.AMDesignator) && !format.Contains(DateTimeFormatInfo.PMDesignator)) + if (!format.Equals("dddd") && !format.Equals(DateTimeFormatInfo.AMDesignator) && !format.Equals(DateTimeFormatInfo.PMDesignator)) { if (format.Contains("M")) dateParts[0] = dates[i]; diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs index 5bc07308..082ec6ab 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs @@ -17,7 +17,7 @@ namespace Microsoft.Windows.Controls private bool _fireSelectionChangedEvent = true; private bool _isSyncingTextAndValueProperties; - private DateTimeParser _dateParser; + private DateTimeParser _dateTimeParser; #endregion //Members @@ -165,8 +165,6 @@ namespace Microsoft.Windows.Controls { base.OnApplyTemplate(); TextBox.SelectionChanged += TextBox_SelectionChanged; - - _dateParser = new DateTimeParser(DateTimeFormatInfo, GetFormatString(Format)); } protected override void OnIncrement() @@ -212,16 +210,20 @@ namespace Microsoft.Windows.Controls protected override void OnTextChanged(string previousValue, string currentValue) { + //TODO: clean this up and make sure it doesn't fire recursively + if (String.IsNullOrEmpty(currentValue)) { Value = null; return; } - //TODO: clean this up and make sure it doesn't fire recursively + if (_dateTimeParser == null) + _dateTimeParser = new DateTimeParser(DateTimeFormatInfo, GetFormatString(Format)); + DateTime current = Value.HasValue ? Value.Value : DateTime.Now; DateTime result; - var success = _dateParser.TryParse(currentValue, out result, current); + var success = _dateTimeParser.TryParse(currentValue, out result, current); SyncTextAndValueProperties(InputBase.TextProperty, result); }