From 8e5c79604a05b2e18d3b3a554ffe03a34df05bed Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Thu, 31 Mar 2011 17:20:59 +0000 Subject: [PATCH] refactored new numeric editors and added the editors to the PropertyGrid control. Now time to start ripping out the old NumericUpDown control. --- .../Implementation/DecimalUpDown.cs | 166 +----------------- .../Implementation/DoubleUpDown.cs | 166 +----------------- .../Implementation/IntegerUpDown.cs | 166 +----------------- .../Implementation/NumericUpDown.cs | 154 ++++++++++++++++ ...UpDownEditor.cs => DecimalUpDownEditor.cs} | 4 +- .../Editors/DoubleUpDownEditor.cs | 12 ++ .../Implementation/PropertyGrid.cs | 6 +- .../WPFToolkit.Extended.csproj | 3 +- 8 files changed, 189 insertions(+), 488 deletions(-) rename ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/{NumericUpDownEditor.cs => DecimalUpDownEditor.cs} (56%) create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DoubleUpDownEditor.cs diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DecimalUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DecimalUpDown.cs index 0ccd7854..352f209d 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DecimalUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DecimalUpDown.cs @@ -1,138 +1,27 @@ using System; -using Microsoft.Windows.Controls.Primitives; using System.Windows; -using System.Windows.Input; namespace Microsoft.Windows.Controls { - public class DecimalUpDown : UpDownBase + public class DecimalUpDown : NumericUpDown { - #region Properties - - #region DefaultValue - - //can possibly be in base class - public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(decimal), typeof(DecimalUpDown), new UIPropertyMetadata(default(decimal))); - public decimal DefaultValue - { - get { return (decimal)GetValue(DefaultValueProperty); } - set { SetValue(DefaultValueProperty, value); } - } - - #endregion //DefaultValue - - #region FormatString - - public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(DecimalUpDown), new UIPropertyMetadata(String.Empty)); - public string FormatString - { - get { return (string)GetValue(FormatStringProperty); } - set { SetValue(FormatStringProperty, value); } - } - - #endregion //FormatString - - #region Increment - - public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(decimal), typeof(DecimalUpDown), new PropertyMetadata(1m)); - public decimal Increment - { - get { return (decimal)GetValue(IncrementProperty); } - set { SetValue(IncrementProperty, value); } - } - - #endregion - - #region Maximum - - public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(decimal), typeof(DecimalUpDown), new UIPropertyMetadata(decimal.MaxValue, OnMaximumChanged)); - public decimal Maximum - { - get { return (decimal)GetValue(MaximumProperty); } - set { SetValue(MaximumProperty, value); } - } - - private static void OnMaximumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) - { - DecimalUpDown decimalUpDown = o as DecimalUpDown; - if (decimalUpDown != null) - decimalUpDown.OnMaximumChanged((decimal)e.OldValue, (decimal)e.NewValue); - } - - protected virtual void OnMaximumChanged(decimal oldValue, decimal newValue) - { - //SetValidSpinDirection(); - } - - #endregion //Maximum - - #region Minimum - - public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(decimal), typeof(DecimalUpDown), new UIPropertyMetadata(decimal.MinValue, OnMinimumChanged)); - public decimal Minimum - { - get { return (decimal)GetValue(MinimumProperty); } - set { SetValue(MinimumProperty, value); } - } - - private static void OnMinimumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) - { - DecimalUpDown decimalUpDown = o as DecimalUpDown; - if (decimalUpDown != null) - decimalUpDown.OnMinimumChanged((decimal)e.OldValue, (decimal)e.NewValue); - } - - protected virtual void OnMinimumChanged(decimal oldValue, decimal newValue) - { - //SetValidSpinDirection(); - } - - #endregion //Minimum - - #region SelectAllOnGotFocus - - public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(DecimalUpDown), new PropertyMetadata(false)); - public bool SelectAllOnGotFocus - { - get { return (bool)GetValue(SelectAllOnGotFocusProperty); } - set { SetValue(SelectAllOnGotFocusProperty, value); } - } - - #endregion //SelectAllOnGotFocus - - #endregion //Properties - #region Constructors static DecimalUpDown() { DefaultStyleKeyProperty.OverrideMetadata(typeof(DecimalUpDown), new FrameworkPropertyMetadata(typeof(DecimalUpDown))); + DefaultValueProperty.OverrideMetadata(typeof(DecimalUpDown), new FrameworkPropertyMetadata(default(decimal))); + IncrementProperty.OverrideMetadata(typeof(DecimalUpDown), new FrameworkPropertyMetadata(1m)); + MaximumProperty.OverrideMetadata(typeof(DecimalUpDown), new FrameworkPropertyMetadata(decimal.MaxValue)); + MinimumProperty.OverrideMetadata(typeof(DecimalUpDown), new FrameworkPropertyMetadata(decimal.MinValue)); } #endregion //Constructors #region Base Class Overrides - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (SelectAllOnGotFocus) - { - //in order to select all the text we must handle both the keybord (tabbing) and mouse (clicking) events - TextBox.GotKeyboardFocus += OnTextBoxGotKeyBoardFocus; - TextBox.PreviewMouseLeftButtonDown += OnTextBoxPreviewMouseLeftButtonDown; - } - - //SetValidSpinDirection(); - } - protected override decimal? OnCoerceValue(decimal? value) { - if (value == null) return value; - - decimal val = value.Value; - if (value < Minimum) return Minimum; else if (value > Maximum) @@ -185,51 +74,6 @@ namespace Microsoft.Windows.Controls return Value.Value.ToString(FormatString, CultureInfo); } - protected override void OnValueChanged(decimal? oldValue, decimal? newValue) - { - //SetValidSpinDirection(); - base.OnValueChanged(oldValue, newValue); - } - #endregion //Base Class Overrides - - #region Event Handlers - - private void OnTextBoxGotKeyBoardFocus(object sender, RoutedEventArgs e) - { - TextBox.SelectAll(); - } - - void OnTextBoxPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - if (!TextBox.IsKeyboardFocused) - { - e.Handled = true; - TextBox.Focus(); - } - } - - #endregion //Event Handlers - - #region Methods - - /// - /// Sets the valid spin direction based on current value, minimum and maximum. - /// - //private void SetValidSpinDirection() - //{ - // ValidSpinDirections validDirections = ValidSpinDirections.None; - - // if (Value < Maximum) - // validDirections = validDirections | ValidSpinDirections.Increase; - - // if (Value > Minimum) - // validDirections = validDirections | ValidSpinDirections.Decrease; - - // if (Spinner != null) - // Spinner.ValidSpinDirection = validDirections; - //} - - #endregion //Methods } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DoubleUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DoubleUpDown.cs index 8248de80..ccb38584 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DoubleUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/DoubleUpDown.cs @@ -1,138 +1,27 @@ using System; -using Microsoft.Windows.Controls.Primitives; using System.Windows; -using System.Windows.Input; namespace Microsoft.Windows.Controls { - public class DoubleUpDown : UpDownBase + public class DoubleUpDown : NumericUpDown { - #region Properties - - #region DefaultValue - - //can possibly be in base class - public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(double), typeof(DoubleUpDown), new UIPropertyMetadata(default(double))); - public double DefaultValue - { - get { return (double)GetValue(DefaultValueProperty); } - set { SetValue(DefaultValueProperty, value); } - } - - #endregion //DefaultValue - - #region FormatString - - public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(DoubleUpDown), new UIPropertyMetadata(String.Empty)); - public string FormatString - { - get { return (string)GetValue(FormatStringProperty); } - set { SetValue(FormatStringProperty, value); } - } - - #endregion //FormatString - - #region Increment - - public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(double), typeof(DoubleUpDown), new PropertyMetadata(1d)); - public double Increment - { - get { return (double)GetValue(IncrementProperty); } - set { SetValue(IncrementProperty, value); } - } - - #endregion - - #region Maximum - - public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(DoubleUpDown), new UIPropertyMetadata(double.MaxValue, OnMaximumChanged)); - public double Maximum - { - get { return (double)GetValue(MaximumProperty); } - set { SetValue(MaximumProperty, value); } - } - - private static void OnMaximumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) - { - DoubleUpDown doubleUpDown = o as DoubleUpDown; - if (doubleUpDown != null) - doubleUpDown.OnMaximumChanged((double)e.OldValue, (double)e.NewValue); - } - - protected virtual void OnMaximumChanged(double oldValue, double newValue) - { - //SetValidSpinDirection(); - } - - #endregion //Maximum - - #region Minimum - - public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), typeof(DoubleUpDown), new UIPropertyMetadata(double.MinValue, OnMinimumChanged)); - public double Minimum - { - get { return (double)GetValue(MinimumProperty); } - set { SetValue(MinimumProperty, value); } - } - - private static void OnMinimumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) - { - DoubleUpDown doubleUpDown = o as DoubleUpDown; - if (doubleUpDown != null) - doubleUpDown.OnMinimumChanged((double)e.OldValue, (double)e.NewValue); - } - - protected virtual void OnMinimumChanged(double oldValue, double newValue) - { - //SetValidSpinDirection(); - } - - #endregion //Minimum - - #region SelectAllOnGotFocus - - public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(DoubleUpDown), new PropertyMetadata(false)); - public bool SelectAllOnGotFocus - { - get { return (bool)GetValue(SelectAllOnGotFocusProperty); } - set { SetValue(SelectAllOnGotFocusProperty, value); } - } - - #endregion //SelectAllOnGotFocus - - #endregion //Properties - #region Constructors static DoubleUpDown() { DefaultStyleKeyProperty.OverrideMetadata(typeof(DoubleUpDown), new FrameworkPropertyMetadata(typeof(DoubleUpDown))); + DefaultValueProperty.OverrideMetadata(typeof(DoubleUpDown), new FrameworkPropertyMetadata(default(double))); + IncrementProperty.OverrideMetadata(typeof(DoubleUpDown), new FrameworkPropertyMetadata(1d)); + MaximumProperty.OverrideMetadata(typeof(DoubleUpDown), new FrameworkPropertyMetadata(double.MaxValue)); + MinimumProperty.OverrideMetadata(typeof(DoubleUpDown), new FrameworkPropertyMetadata(double.MinValue)); } #endregion //Constructors #region Base Class Overrides - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (SelectAllOnGotFocus) - { - //in order to select all the text we must handle both the keybord (tabbing) and mouse (clicking) events - TextBox.GotKeyboardFocus += OnTextBoxGotKeyBoardFocus; - TextBox.PreviewMouseLeftButtonDown += OnTextBoxPreviewMouseLeftButtonDown; - } - - //SetValidSpinDirection(); - } - protected override double? OnCoerceValue(double? value) { - if (value == null) return value; - - double val = value.Value; - if (value < Minimum) return Minimum; else if (value > Maximum) @@ -185,51 +74,6 @@ namespace Microsoft.Windows.Controls return Value.Value.ToString(FormatString, CultureInfo); } - protected override void OnValueChanged(double? oldValue, double? newValue) - { - //SetValidSpinDirection(); - base.OnValueChanged(oldValue, newValue); - } - #endregion //Base Class Overrides - - #region Event Handlers - - private void OnTextBoxGotKeyBoardFocus(object sender, RoutedEventArgs e) - { - TextBox.SelectAll(); - } - - void OnTextBoxPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - if (!TextBox.IsKeyboardFocused) - { - e.Handled = true; - TextBox.Focus(); - } - } - - #endregion //Event Handlers - - #region Methods - - /// - /// Sets the valid spin direction based on current value, minimum and maximum. - /// - //private void SetValidSpinDirection() - //{ - // ValidSpinDirections validDirections = ValidSpinDirections.None; - - // if (Value < Maximum) - // validDirections = validDirections | ValidSpinDirections.Increase; - - // if (Value > Minimum) - // validDirections = validDirections | ValidSpinDirections.Decrease; - - // if (Spinner != null) - // Spinner.ValidSpinDirection = validDirections; - //} - - #endregion //Methods } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/IntegerUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/IntegerUpDown.cs index 00af6d7f..5d61361d 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/IntegerUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/IntegerUpDown.cs @@ -1,138 +1,27 @@ using System; using System.Windows; -using System.Windows.Input; -using Microsoft.Windows.Controls.Primitives; namespace Microsoft.Windows.Controls { - public class IntegerUpDown : UpDownBase + public class IntegerUpDown : NumericUpDown { - #region Properties - - #region DefaultValue - - //can possibly be in base class - public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(int), typeof(IntegerUpDown), new UIPropertyMetadata(default(int))); - public int DefaultValue - { - get { return (int)GetValue(DefaultValueProperty); } - set { SetValue(DefaultValueProperty, value); } - } - - #endregion //DefaultValue - - #region FormatString - - public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(IntegerUpDown), new UIPropertyMetadata(String.Empty)); - public string FormatString - { - get { return (string)GetValue(FormatStringProperty); } - set { SetValue(FormatStringProperty, value); } - } - - #endregion //FormatString - - #region Increment - - public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(int), typeof(IntegerUpDown), new PropertyMetadata(1)); - public int Increment - { - get { return (int)GetValue(IncrementProperty); } - set { SetValue(IncrementProperty, value); } - } - - #endregion - - #region Maximum - - public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(int), typeof(IntegerUpDown), new UIPropertyMetadata(int.MaxValue, OnMaximumChanged)); - public int Maximum - { - get { return (int)GetValue(MaximumProperty); } - set { SetValue(MaximumProperty, value); } - } - - private static void OnMaximumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) - { - IntegerUpDown integerUpDown = o as IntegerUpDown; - if (integerUpDown != null) - integerUpDown.OnMaximumChanged((int)e.OldValue, (int)e.NewValue); - } - - protected virtual void OnMaximumChanged(int oldValue, int newValue) - { - //SetValidSpinDirection(); - } - - #endregion //Maximum - - #region Minimum - - public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(int), typeof(IntegerUpDown), new UIPropertyMetadata(int.MinValue, OnMinimumChanged)); - public int Minimum - { - get { return (int)GetValue(MinimumProperty); } - set { SetValue(MinimumProperty, value); } - } - - private static void OnMinimumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) - { - IntegerUpDown integerUpDown = o as IntegerUpDown; - if (integerUpDown != null) - integerUpDown.OnMinimumChanged((int)e.OldValue, (int)e.NewValue); - } - - protected virtual void OnMinimumChanged(int oldValue, int newValue) - { - //SetValidSpinDirection(); - } - - #endregion //Minimum - - #region SelectAllOnGotFocus - - public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(IntegerUpDown), new PropertyMetadata(false)); - public bool SelectAllOnGotFocus - { - get { return (bool)GetValue(SelectAllOnGotFocusProperty); } - set { SetValue(SelectAllOnGotFocusProperty, value); } - } - - #endregion //SelectAllOnGotFocus - - #endregion //Properties - #region Constructors static IntegerUpDown() { DefaultStyleKeyProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(typeof(IntegerUpDown))); + DefaultValueProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(0)); + IncrementProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(1)); + MaximumProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(int.MaxValue)); + MinimumProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(int.MinValue)); } #endregion //Constructors #region Base Class Overrides - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (SelectAllOnGotFocus) - { - //in order to select all the text we must handle both the keybord (tabbing) and mouse (clicking) events - TextBox.GotKeyboardFocus += OnTextBoxGotKeyBoardFocus; - TextBox.PreviewMouseLeftButtonDown += OnTextBoxPreviewMouseLeftButtonDown; - } - - //SetValidSpinDirection(); - } - protected override int? OnCoerceValue(int? value) { - if (value == null) return value; - - int val = value.Value; - if (value < Minimum) return Minimum; else if (value > Maximum) @@ -185,51 +74,6 @@ namespace Microsoft.Windows.Controls return Value.Value.ToString(FormatString, CultureInfo); } - protected override void OnValueChanged(int? oldValue, int? newValue) - { - //SetValidSpinDirection(); - base.OnValueChanged(oldValue, newValue); - } - #endregion //Base Class Overrides - - #region Event Handlers - - private void OnTextBoxGotKeyBoardFocus(object sender, RoutedEventArgs e) - { - TextBox.SelectAll(); - } - - void OnTextBoxPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - if (!TextBox.IsKeyboardFocused) - { - e.Handled = true; - TextBox.Focus(); - } - } - - #endregion //Event Handlers - - #region Methods - - /// - /// Sets the valid spin direction based on current value, minimum and maximum. - /// - //private void SetValidSpinDirection() - //{ - // ValidSpinDirections validDirections = ValidSpinDirections.None; - - // if (Value < Maximum) - // validDirections = validDirections | ValidSpinDirections.Increase; - - // if (Value > Minimum) - // validDirections = validDirections | ValidSpinDirections.Decrease; - - // if (Spinner != null) - // Spinner.ValidSpinDirection = validDirections; - //} - - #endregion //Methods } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs index 764278d3..6ef73ee1 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs @@ -363,4 +363,158 @@ namespace Microsoft.Windows.Controls #endregion //Methods } + + public abstract class NumericUpDown : UpDownBase + { + #region Properties + + #region DefaultValue + + public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(T), typeof(NumericUpDown), new UIPropertyMetadata(default(T))); + public T DefaultValue + { + get { return (T)GetValue(DefaultValueProperty); } + set { SetValue(DefaultValueProperty, value); } + } + + #endregion //DefaultValue + + #region FormatString + + public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(NumericUpDown), new UIPropertyMetadata(String.Empty)); + public string FormatString + { + get { return (string)GetValue(FormatStringProperty); } + set { SetValue(FormatStringProperty, value); } + } + + #endregion //FormatString + + #region Increment + + public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(T), typeof(NumericUpDown), new PropertyMetadata(default(T))); + public T Increment + { + get { return (T)GetValue(IncrementProperty); } + set { SetValue(IncrementProperty, value); } + } + + #endregion + + #region Maximum + + public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(T), typeof(NumericUpDown), new UIPropertyMetadata(default(T), OnMaximumChanged)); + public T Maximum + { + get { return (T)GetValue(MaximumProperty); } + set { SetValue(MaximumProperty, value); } + } + + private static void OnMaximumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + NumericUpDown integerUpDown = o as NumericUpDown; + if (integerUpDown != null) + integerUpDown.OnMaximumChanged((T)e.OldValue, (T)e.NewValue); + } + + protected virtual void OnMaximumChanged(T oldValue, T newValue) + { + //SetValidSpinDirection(); + } + + #endregion //Maximum + + #region Minimum + + public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(T), typeof(NumericUpDown), new UIPropertyMetadata(default(T), OnMinimumChanged)); + public T Minimum + { + get { return (T)GetValue(MinimumProperty); } + set { SetValue(MinimumProperty, value); } + } + + private static void OnMinimumChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) + { + NumericUpDown integerUpDown = o as NumericUpDown; + if (integerUpDown != null) + integerUpDown.OnMinimumChanged((T)e.OldValue, (T)e.NewValue); + } + + protected virtual void OnMinimumChanged(T oldValue, T newValue) + { + //SetValidSpinDirection(); + } + + #endregion //Minimum + + #region SelectAllOnGotFocus + + public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register("SelectAllOnGotFocus", typeof(bool), typeof(NumericUpDown), new PropertyMetadata(false)); + public bool SelectAllOnGotFocus + { + get { return (bool)GetValue(SelectAllOnGotFocusProperty); } + set { SetValue(SelectAllOnGotFocusProperty, value); } + } + + #endregion //SelectAllOnGotFocus + + #endregion //Properties + + #region Base Class Overrides + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + if (SelectAllOnGotFocus) + { + //in order to select all the text we must handle both the keybord (tabbing) and mouse (clicking) events + TextBox.GotKeyboardFocus += OnTextBoxGotKeyBoardFocus; + TextBox.PreviewMouseLeftButtonDown += OnTextBoxPreviewMouseLeftButtonDown; + } + + //SetValidSpinDirection(); + } + + #endregion //Base Class Overrides + + #region Event Handlers + + private void OnTextBoxGotKeyBoardFocus(object sender, RoutedEventArgs e) + { + TextBox.SelectAll(); + } + + void OnTextBoxPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (!TextBox.IsKeyboardFocused) + { + e.Handled = true; + TextBox.Focus(); + } + } + + #endregion //Event Handlers + + #region Methods + + /// + /// Sets the valid spin direction based on current value, minimum and maximum. + /// + //private void SetValidSpinDirection() + //{ + // ValidSpinDirections validDirections = ValidSpinDirections.None; + + // if (Value < Maximum) + // validDirections = validDirections | ValidSpinDirections.Increase; + + // if (Value > Minimum) + // validDirections = validDirections | ValidSpinDirections.Decrease; + + // if (Spinner != null) + // Spinner.ValidSpinDirection = validDirections; + //} + + #endregion //Methods + } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/NumericUpDownEditor.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DecimalUpDownEditor.cs similarity index 56% rename from ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/NumericUpDownEditor.cs rename to ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DecimalUpDownEditor.cs index 283106bd..7e8e9e28 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/NumericUpDownEditor.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DecimalUpDownEditor.cs @@ -2,11 +2,11 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors { - public class NumericUpDownEditor : TypeEditor + public class DecimalUpDownEditor : TypeEditor { protected override void SetValueDependencyProperty() { - ValueProperty = NumericUpDown.ValueProperty; + ValueProperty = DecimalUpDown.ValueProperty; } } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DoubleUpDownEditor.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DoubleUpDownEditor.cs new file mode 100644 index 00000000..28551aea --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DoubleUpDownEditor.cs @@ -0,0 +1,12 @@ +using System; + +namespace Microsoft.Windows.Controls.PropertyGrid.Editors +{ + public class DoubleUpDownEditor : TypeEditor + { + protected override void SetValueDependencyProperty() + { + ValueProperty = DoubleUpDown.ValueProperty; + } + } +} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs index 9ac9e05a..49057cfb 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs @@ -322,8 +322,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid editor = new TextBlockEditor(); else if (propertyItem.PropertyType == typeof(bool)) editor = new CheckBoxEditor(); - //else if (propertyItem.PropertyType == typeof(double)) - // editor = new NumericUpDownEditor(); + else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?)) + editor = new DecimalUpDownEditor(); + else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?)) + editor = new DoubleUpDownEditor(); else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?)) editor = new IntegerUpDownEditor(); else if (propertyItem.PropertyType == typeof(DateTime)) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj index f23c01aa..bcc065fc 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj @@ -211,12 +211,13 @@ + + -