Browse Source

DateTimeUpDown: added support for custom format. Simply specify the Format as Custom and then provide a FormatString.

<extToolkit:DateTimeUpDown Format="Custom" FormatString="HH:mm" Value="1:30:00 PM" />

Above snippet will show as 13:30
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
4cc111cd09
  1. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeFormat.cs
  2. 32
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeUpDown.cs

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/DateTimeFormat.cs

@ -4,6 +4,7 @@ namespace Microsoft.Windows.Controls
{
public enum DateTimeFormat
{
Custom,
FullDateTime,
LongDate,
LongTime,

32
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");
}

Loading…
Cancel
Save