From ce31bb0c7a630f5e7277cc02a8bcb126b5c33927 Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Sun, 13 Mar 2011 18:55:59 +0000 Subject: [PATCH] PropertyGrid: added NumericUpDown type editor for double and int. --- .../Implementation/NumericUpDown.cs | 27 ++++++++++++++++--- .../NumericUpDown/Themes/Generic.xaml | 1 - .../Editors/IntegerUpDownEditor.cs | 14 ++++++++++ .../Editors/NumericUpDownEditor.cs | 19 +++++++++++++ .../Implementation/PropertyGrid.cs | 4 +++ .../Implementation/PropertyItem.cs | 5 +--- .../WPFToolkit.Extended.csproj | 2 ++ 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/NumericUpDownEditor.cs diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs index 86497db3..bacbff39 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs @@ -57,7 +57,7 @@ namespace Microsoft.Windows.Controls #region FormatString - public static readonly DependencyProperty StringFormatProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(NumericUpDown), new PropertyMetadata("F0", OnStringFormatPropertyPropertyChanged)); + public static readonly DependencyProperty StringFormatProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(NumericUpDown), new PropertyMetadata(string.Empty, OnStringFormatPropertyPropertyChanged)); public string FormatString { get { return (string)GetValue(StringFormatProperty); } @@ -124,6 +124,12 @@ namespace Microsoft.Windows.Controls base.OnAccessKey(e); } + protected override void OnGotFocus(RoutedEventArgs e) + { + if (TextBox != null) + TextBox.Focus(); + } + protected override void OnValueChanged(object oldValue, object newValue) { SetValidSpinDirection(); @@ -171,18 +177,31 @@ namespace Microsoft.Windows.Controls protected override string ConvertValueToText(object value) { - return (Convert.ToDecimal(Value)).ToString(FormatString, CultureInfo.CurrentCulture); + //TODO: create GetTextFromValue methods for each data type; + if (value is double) + { + double d = (double)value; + + if (Double.IsNaN(d)) + return "NaN"; + else if (Double.IsPositiveInfinity(d) || Double.MaxValue == d) + return "Infinity"; + else if (Double.IsNegativeInfinity(d) || Double.MinValue == d) + return "Negative-Infinity"; + } + + return (Convert.ToDouble(Value)).ToString(FormatString, CultureInfo.CurrentCulture); } protected override void OnIncrement() { - double newValue = (double)(Convert.ToDecimal(Value) + (decimal)Increment); + double newValue = (double)(Convert.ToDouble(Value) + (double)Increment); Value = ValueType != typeof(Double) ? Convert.ChangeType(newValue, ValueType) : newValue; } protected override void OnDecrement() { - double newValue = (double)(Convert.ToDecimal(Value) - (decimal)Increment); + double newValue = (double)(Convert.ToDouble(Value) - (double)Increment); Value = ValueType != typeof(Double) ? Convert.ChangeType(newValue, ValueType) : newValue; } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml index 4606a868..c73b0d29 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml @@ -11,7 +11,6 @@