From 0669e78ec71b4d3ed664ff2591eb9cf12aa2f21a Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Tue, 29 Mar 2011 14:57:12 +0000 Subject: [PATCH] NumericUpDown and DateTimeUpDown: added NullValue property which allows you to set a default value if the bound value is null. The NullValue will be used when the increment/decrement buttons are pressed on a null value. --- .../Implementation/DateTimeUpDown.cs | 20 +++++++++++++++++-- .../Implementation/NumericUpDown.cs | 16 +++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs index 05f0bcdd..f2857cf6 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs @@ -75,6 +75,18 @@ namespace Microsoft.Windows.Controls #endregion //FormatString + #region NullValue + + public static readonly DependencyProperty NullValueProperty = DependencyProperty.Register("NullValue", typeof(DateTime), typeof(DateTimeUpDown), new UIPropertyMetadata(DateTime.Now)); + public DateTime NullValue + { + get { return (DateTime)GetValue(NullValueProperty); } + set { SetValue(NullValueProperty, value); } + } + + + #endregion //NullValue + #region Value public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(DateTime?), typeof(DateTimeUpDown), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, OnCoerceValue)); @@ -215,14 +227,18 @@ namespace Microsoft.Windows.Controls protected override void OnIncrement() { - if (Value != null) + if (Value.HasValue) UpdateDateTime(1); + else + Value = NullValue; } protected override void OnDecrement() { - if (Value != null) + if (Value.HasValue) UpdateDateTime(-1); + else + Value = NullValue; } #endregion //Abstract diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs index 117a7a31..2e054b71 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs @@ -86,6 +86,18 @@ namespace Microsoft.Windows.Controls #endregion //FormatString + #region NullValue + + public static readonly DependencyProperty NullValueProperty = DependencyProperty.Register("NullValue", typeof(decimal), typeof(NumericUpDown), new UIPropertyMetadata(default(decimal))); + public decimal NullValue + { + get { return (decimal)GetValue(NullValueProperty); } + set { SetValue(NullValueProperty, value); } + } + + + #endregion //NullValue + #region SelectAllOnGotFocus public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(NumericUpDown), new PropertyMetadata(false)); @@ -199,12 +211,16 @@ namespace Microsoft.Windows.Controls { if (Value.HasValue) Value += Increment; + else + Value = NullValue; } protected override void OnDecrement() { if (Value.HasValue) Value -= Increment; + else + Value = NullValue; } protected override void OnPreviewKeyDown(KeyEventArgs e)