|
|
@ -17,14 +17,10 @@ namespace Microsoft.Windows.Controls |
|
|
private bool _fireSelectionChangedEvent = true; |
|
|
private bool _fireSelectionChangedEvent = true; |
|
|
private bool _processTextChanged = true; |
|
|
private bool _processTextChanged = true; |
|
|
|
|
|
|
|
|
private DateTimeParser _dateTimeParser; |
|
|
|
|
|
|
|
|
|
|
|
#endregion //Members
|
|
|
#endregion //Members
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
private DateTimeFormatInfo DateTimeFormatInfo { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
#region DefaultValue
|
|
|
#region DefaultValue
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(DateTime), typeof(DateTimeUpDown), new UIPropertyMetadata(DateTime.Now)); |
|
|
public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(DateTime), typeof(DateTimeUpDown), new UIPropertyMetadata(DateTime.Now)); |
|
|
@ -54,7 +50,6 @@ namespace Microsoft.Windows.Controls |
|
|
|
|
|
|
|
|
protected virtual void OnFormatChanged(DateTimeFormat oldValue, DateTimeFormat newValue) |
|
|
protected virtual void OnFormatChanged(DateTimeFormat oldValue, DateTimeFormat newValue) |
|
|
{ |
|
|
{ |
|
|
_dateTimeParser.Format = GetFormatString(newValue); |
|
|
|
|
|
InitializeDateTimeInfoListAndParseValue(); |
|
|
InitializeDateTimeInfoListAndParseValue(); |
|
|
UpdateTextFormatting(); |
|
|
UpdateTextFormatting(); |
|
|
} |
|
|
} |
|
|
@ -82,7 +77,6 @@ namespace Microsoft.Windows.Controls |
|
|
if (string.IsNullOrEmpty(newValue)) |
|
|
if (string.IsNullOrEmpty(newValue)) |
|
|
throw new ArgumentException("FormatString should be specified.", "newValue"); |
|
|
throw new ArgumentException("FormatString should be specified.", "newValue"); |
|
|
|
|
|
|
|
|
_dateTimeParser.Format = newValue; |
|
|
|
|
|
InitializeDateTimeInfoListAndParseValue(); |
|
|
InitializeDateTimeInfoListAndParseValue(); |
|
|
UpdateTextFormatting(); |
|
|
UpdateTextFormatting(); |
|
|
} |
|
|
} |
|
|
@ -112,8 +106,6 @@ namespace Microsoft.Windows.Controls |
|
|
|
|
|
|
|
|
public DateTimeUpDown() |
|
|
public DateTimeUpDown() |
|
|
{ |
|
|
{ |
|
|
DateTimeFormatInfo = DateTimeFormatInfo.GetInstance(CultureInfo); |
|
|
|
|
|
_dateTimeParser = new DateTimeParser(DateTimeFormatInfo, GetFormatString(Format)); |
|
|
|
|
|
InitializeDateTimeInfoList(); |
|
|
InitializeDateTimeInfoList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -127,6 +119,11 @@ namespace Microsoft.Windows.Controls |
|
|
TextBox.SelectionChanged += TextBox_SelectionChanged; |
|
|
TextBox.SelectionChanged += TextBox_SelectionChanged; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override void OnCultureInfoChanged(CultureInfo oldValue, CultureInfo newValue) |
|
|
|
|
|
{ |
|
|
|
|
|
InitializeDateTimeInfoList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override DateTime? CoerceValue(DateTime? value) |
|
|
protected override DateTime? CoerceValue(DateTime? value) |
|
|
{ |
|
|
{ |
|
|
//TODO: implement Minimum and Maximum
|
|
|
//TODO: implement Minimum and Maximum
|
|
|
@ -187,11 +184,11 @@ namespace Microsoft.Windows.Controls |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
DateTime current = Value.HasValue ? Value.Value : DateTime.Now; |
|
|
DateTime current = Value.HasValue ? Value.Value : DateTime.Parse(DateTime.Now.ToString(), CultureInfo.DateTimeFormat); |
|
|
DateTime result; |
|
|
DateTime result; |
|
|
var success = _dateTimeParser.TryParse(currentValue, out result, current); |
|
|
var success = DateTimeParser.TryParse(currentValue, GetFormatString(Format), current, CultureInfo, out result); |
|
|
|
|
|
|
|
|
SyncTextAndValueProperties(InputBase.TextProperty, result.ToString()); |
|
|
SyncTextAndValueProperties(InputBase.TextProperty, result.ToString(CultureInfo)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected override DateTime? ConvertTextToValue(string text) |
|
|
protected override DateTime? ConvertTextToValue(string text) |
|
|
@ -199,15 +196,16 @@ namespace Microsoft.Windows.Controls |
|
|
if (string.IsNullOrEmpty(text)) |
|
|
if (string.IsNullOrEmpty(text)) |
|
|
return null; |
|
|
return null; |
|
|
|
|
|
|
|
|
return DateTime.Parse(text, CultureInfo.CurrentCulture); |
|
|
return DateTime.Parse(text, CultureInfo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected override string ConvertValueToText() |
|
|
protected override string ConvertValueToText() |
|
|
{ |
|
|
{ |
|
|
if (Value == null) return string.Empty; |
|
|
if (Value == null) return string.Empty; |
|
|
|
|
|
|
|
|
DateTime dt = DateTime.Parse(Value.ToString(), CultureInfo); |
|
|
var test = Value.Value.ToString(CultureInfo); |
|
|
return dt.ToString(GetFormatString(Format), CultureInfo); |
|
|
|
|
|
|
|
|
return Value.Value.ToString(GetFormatString(Format), CultureInfo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected override void SetValidSpinDirection() |
|
|
protected override void SetValidSpinDirection() |
|
|
@ -437,7 +435,7 @@ namespace Microsoft.Windows.Controls |
|
|
{ |
|
|
{ |
|
|
DateTime date = DateTime.Parse(Value.ToString()); |
|
|
DateTime date = DateTime.Parse(Value.ToString()); |
|
|
info.StartPosition = text.Length; |
|
|
info.StartPosition = text.Length; |
|
|
info.Content = date.ToString(info.Format, DateTimeFormatInfo); |
|
|
info.Content = date.ToString(info.Format, CultureInfo.DateTimeFormat); |
|
|
info.Length = info.Content.Length; |
|
|
info.Length = info.Content.Length; |
|
|
text += info.Content; |
|
|
text += info.Content; |
|
|
} |
|
|
} |
|
|
@ -469,25 +467,25 @@ namespace Microsoft.Windows.Controls |
|
|
switch (dateTimeFormat) |
|
|
switch (dateTimeFormat) |
|
|
{ |
|
|
{ |
|
|
case DateTimeFormat.ShortDate: |
|
|
case DateTimeFormat.ShortDate: |
|
|
return DateTimeFormatInfo.ShortDatePattern; |
|
|
return CultureInfo.DateTimeFormat.ShortDatePattern; |
|
|
case DateTimeFormat.LongDate: |
|
|
case DateTimeFormat.LongDate: |
|
|
return DateTimeFormatInfo.LongDatePattern; |
|
|
return CultureInfo.DateTimeFormat.LongDatePattern; |
|
|
case DateTimeFormat.ShortTime: |
|
|
case DateTimeFormat.ShortTime: |
|
|
return DateTimeFormatInfo.ShortTimePattern; |
|
|
return CultureInfo.DateTimeFormat.ShortTimePattern; |
|
|
case DateTimeFormat.LongTime: |
|
|
case DateTimeFormat.LongTime: |
|
|
return DateTimeFormatInfo.LongTimePattern; |
|
|
return CultureInfo.DateTimeFormat.LongTimePattern; |
|
|
case DateTimeFormat.FullDateTime: |
|
|
case DateTimeFormat.FullDateTime: |
|
|
return DateTimeFormatInfo.FullDateTimePattern; |
|
|
return CultureInfo.DateTimeFormat.FullDateTimePattern; |
|
|
case DateTimeFormat.MonthDay: |
|
|
case DateTimeFormat.MonthDay: |
|
|
return DateTimeFormatInfo.MonthDayPattern; |
|
|
return CultureInfo.DateTimeFormat.MonthDayPattern; |
|
|
case DateTimeFormat.RFC1123: |
|
|
case DateTimeFormat.RFC1123: |
|
|
return DateTimeFormatInfo.RFC1123Pattern; |
|
|
return CultureInfo.DateTimeFormat.RFC1123Pattern; |
|
|
case DateTimeFormat.SortableDateTime: |
|
|
case DateTimeFormat.SortableDateTime: |
|
|
return DateTimeFormatInfo.SortableDateTimePattern; |
|
|
return CultureInfo.DateTimeFormat.SortableDateTimePattern; |
|
|
case DateTimeFormat.UniversalSortableDateTime: |
|
|
case DateTimeFormat.UniversalSortableDateTime: |
|
|
return DateTimeFormatInfo.UniversalSortableDateTimePattern; |
|
|
return CultureInfo.DateTimeFormat.UniversalSortableDateTimePattern; |
|
|
case DateTimeFormat.YearMonth: |
|
|
case DateTimeFormat.YearMonth: |
|
|
return DateTimeFormatInfo.YearMonthPattern; |
|
|
return CultureInfo.DateTimeFormat.YearMonthPattern; |
|
|
case DateTimeFormat.Custom: |
|
|
case DateTimeFormat.Custom: |
|
|
return FormatString; |
|
|
return FormatString; |
|
|
default: |
|
|
default: |
|
|
|