Browse Source

PropertyGrid: added NumericUpDown type editor for double and int.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
ce31bb0c7a
  1. 27
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs
  2. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml
  3. 14
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs
  4. 19
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/NumericUpDownEditor.cs
  5. 4
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  6. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs
  7. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

27
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;
}

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml

@ -11,7 +11,6 @@
<Style TargetType="{x:Type local:NumericUpDown}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NumericUpDown}">

14
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs

@ -0,0 +1,14 @@
using System;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class IntegerUpDownEditor : NumericUpDownEditor
{
protected override void SetEditorProperties()
{
NumericUpDown nud = (NumericUpDown)Editor;
nud.ValueType = typeof(int);
nud.FormatString = "F0";
}
}
}

19
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/NumericUpDownEditor.cs

@ -0,0 +1,19 @@
using System;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class NumericUpDownEditor : TypeEditor
{
protected override void Initialize()
{
Editor = new NumericUpDown();
ValueProperty = NumericUpDown.ValueProperty;
SetEditorProperties();
}
protected virtual void SetEditorProperties()
{
//TODO: override in derived classes to specify custom value type
}
}
}

4
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs

@ -283,6 +283,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid
{
if (propertyItem.PropertyType == typeof(bool))
editor = new CheckBoxEditor();
else if (propertyItem.PropertyType == typeof(int))
editor = new IntegerUpDownEditor();
else if (propertyItem.PropertyType == typeof(double))
editor = new NumericUpDownEditor();
else if (propertyItem.PropertyType.IsEnum)
editor = new EnumComboBoxEditor();
else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))

5
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs

@ -129,13 +129,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region Base Class Overrides
protected override void OnPreviewMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
IsSelected = true;
}
protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
if (Editor != null)
Editor.Focus();

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -172,7 +172,9 @@
<Compile Include="PropertyGrid\Implementation\Editors\EnumComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\FontComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ICustomTypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\IntegerUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ITypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\NumericUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TextBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" />

Loading…
Cancel
Save