diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeFormat.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeFormat.cs index 64591695..f6c54305 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeFormat.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeFormat.cs @@ -4,6 +4,7 @@ namespace Microsoft.Windows.Controls { public enum DateTimeFormat { + Custom, FullDateTime, LongDate, LongTime, diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeUpDown.cs index 0af73e15..73608120 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeUpDown.cs @@ -38,11 +38,39 @@ namespace Microsoft.Windows.Controls protected virtual void OnFormatChanged(DateTimeFormat oldValue, DateTimeFormat newValue) { - InitializeDateTimeInfoList(); + //if using a CustomFormat then the initialization occurs on the CustomFormatString property + if (newValue != DateTimeFormat.Custom) + InitializeDateTimeInfoList(); } #endregion //Format + #region FormatString + + public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(DateTimeUpDown), new UIPropertyMetadata(default(String), OnFormatStringChanged)); + public string FormatString + { + get { return (string)GetValue(FormatStringProperty); } + set { SetValue(FormatStringProperty, value); } + } + + private static void OnFormatStringChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + DateTimeUpDown dateTimeUpDown = o as DateTimeUpDown; + if (dateTimeUpDown != null) + dateTimeUpDown.OnFormatStringChanged((string)e.OldValue, (string)e.NewValue); + } + + protected virtual void OnFormatStringChanged(string oldValue, string newValue) + { + if (string.IsNullOrEmpty(newValue)) + throw new ArgumentException("CustomFormat should be specified.", FormatString); + + InitializeDateTimeInfoList(); + } + + #endregion //FormatString + #endregion //Properties #region Constructors @@ -369,6 +397,8 @@ namespace Microsoft.Windows.Controls return DateTimeFormatInfo.UniversalSortableDateTimePattern; case DateTimeFormat.YearMonth: return DateTimeFormatInfo.YearMonthPattern; + case DateTimeFormat.Custom: + return FormatString; default: throw new ArgumentException("Not a supported format"); }