Browse Source

removed NumericUpDown control.

pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
b7b88c6903
  1. 17
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs
  2. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CalculatorUpDown/Implementation/CalculatorUpDown.cs
  3. 200
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/UpDownBase.cs
  4. 147
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs
  5. 359
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs
  6. 38
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Themes/Generic.xaml

17
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Calculator/Implementation/Calculator.cs

@ -142,16 +142,16 @@ namespace Microsoft.Windows.Controls
{
get { return (int)GetValue(PrecisionProperty); }
set { SetValue(PrecisionProperty, value); }
}
}
#endregion //Precision
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(decimal), typeof(Calculator), new FrameworkPropertyMetadata(default(decimal), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged));
public decimal Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(decimal?), typeof(Calculator), new FrameworkPropertyMetadata(default(decimal), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged));
public decimal? Value
{
get { return (decimal)GetValue(ValueProperty); }
get { return (decimal?)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
@ -159,12 +159,15 @@ namespace Microsoft.Windows.Controls
{
Calculator calculator = o as Calculator;
if (calculator != null)
calculator.OnValueChanged((decimal)e.OldValue, (decimal)e.NewValue);
calculator.OnValueChanged((decimal?)e.OldValue, (decimal?)e.NewValue);
}
protected virtual void OnValueChanged(decimal oldValue, decimal newValue)
protected virtual void OnValueChanged(decimal? oldValue, decimal? newValue)
{
DisplayText = newValue.ToString();
if (newValue.HasValue)
DisplayText = newValue.ToString();
else
DisplayText = "0";
}
#endregion //Value

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/CalculatorUpDown/Implementation/CalculatorUpDown.cs

@ -5,7 +5,7 @@ using System.Windows.Controls.Primitives;
namespace Microsoft.Windows.Controls
{
public class CalculatorUpDown : NumericUpDown
public class CalculatorUpDown : DecimalUpDown
{
#region Members

200
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/UpDownBase.cs

@ -7,200 +7,6 @@ using System.Windows.Data;
namespace Microsoft.Windows.Controls.Primitives
{
public abstract class UpDownBase : InputBase
{
#region Members
/// <summary>
/// Name constant for Text template part.
/// </summary>
internal const string ElementTextName = "TextBox";
/// <summary>
/// Name constant for Spinner template part.
/// </summary>
internal const string ElementSpinnerName = "Spinner";
#endregion //Members
#region Properties
#region AllowSpin
public static readonly DependencyProperty AllowSpinProperty = DependencyProperty.Register("AllowSpin", typeof(bool), typeof(UpDownBase), new UIPropertyMetadata(true));
public bool AllowSpin
{
get { return (bool)GetValue(AllowSpinProperty); }
set { SetValue(AllowSpinProperty, value); }
}
#endregion //AllowSpin
#region ShowButtonSpinner
public static readonly DependencyProperty ShowButtonSpinnerProperty = DependencyProperty.Register("ShowButtonSpinner", typeof(bool), typeof(UpDownBase), new UIPropertyMetadata(true));
public bool ShowButtonSpinner
{
get { return (bool)GetValue(ShowButtonSpinnerProperty); }
set { SetValue(ShowButtonSpinnerProperty, value); }
}
#endregion //ShowButtonSpinner
protected TextBox TextBox { get; private set; }
private Spinner _spinner;
internal Spinner Spinner
{
get { return _spinner; }
private set
{
_spinner = value;
_spinner.Spin += OnSpinnerSpin;
}
}
#endregion //Properties
#region Constructors
internal UpDownBase() { }
#endregion //Constructors
#region Base Class Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
TextBox = GetTemplateChild(ElementTextName) as TextBox;
Spinner = GetTemplateChild(ElementSpinnerName) as Spinner;
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
switch (e.Key)
{
case Key.Up:
{
if (AllowSpin)
DoIncrement();
e.Handled = true;
break;
}
case Key.Down:
{
if (AllowSpin)
DoDecrement();
e.Handled = true;
break;
}
//case Key.Enter:
// {
// if (IsEditable)
// SyncTextAndValueProperties(UpDownBase.TextProperty, TextBox.Text);
// break;
// }
}
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
if (!e.Handled && AllowSpin)
{
if (e.Delta < 0)
{
DoDecrement();
}
else if (0 < e.Delta)
{
DoIncrement();
}
e.Handled = true;
}
}
#endregion //Base Class Overrides
#region Event Handlers
private void OnSpinnerSpin(object sender, SpinEventArgs e)
{
if (AllowSpin)
OnSpin(e);
}
#endregion //Event Handlers
#region Methods
protected virtual void OnSpin(SpinEventArgs e)
{
if (e == null)
throw new ArgumentNullException("e");
if (e.Direction == SpinDirection.Increase)
DoIncrement();
else
DoDecrement();
}
/// <summary>
/// Performs an increment if conditions allow it.
/// </summary>
private void DoDecrement()
{
if (Spinner == null || (Spinner.ValidSpinDirection & ValidSpinDirections.Decrease) == ValidSpinDirections.Decrease)
{
OnDecrement();
}
}
/// <summary>
/// Performs a decrement if conditions allow it.
/// </summary>
private void DoIncrement()
{
if (Spinner == null || (Spinner.ValidSpinDirection & ValidSpinDirections.Increase) == ValidSpinDirections.Increase)
{
OnIncrement();
}
}
#region Abstract
/// <summary>
/// Called by OnSpin when the spin direction is SpinDirection.Increase.
/// </summary>
protected abstract void OnIncrement();
/// <summary>
/// Called by OnSpin when the spin direction is SpinDirection.Descrease.
/// </summary>
protected abstract void OnDecrement();
#endregion //Abstract
#endregion //Methods
}
/// <summary>
/// This is going to be the new UpDownBase class. In order to reliably support the different numeric data types, I need to create a specific control for each data type.
/// So instead of copying and pasting I am going to try to create a generic base class that has most of the logic in it. This will make the NumericUpDown control obsolete
/// and it will be removed from the toolkit. The new controls will be DecimalUpDown, DoubleUpDown, and IntegerUpDown.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class UpDownBase<T> : InputBase
{
#region Members
@ -281,10 +87,10 @@ namespace Microsoft.Windows.Controls.Primitives
protected virtual void OnValueChanged(T oldValue, T newValue)
{
SyncTextAndValueProperties(NumericUpDown.ValueProperty, string.Empty);
SyncTextAndValueProperties(ValueProperty, string.Empty);
RoutedPropertyChangedEventArgs<T> args = new RoutedPropertyChangedEventArgs<T>(oldValue, newValue);
args.RoutedEvent = NumericUpDown.ValueChangedEvent;
args.RoutedEvent = ValueChangedEvent;
RaiseEvent(args);
}
@ -435,7 +241,7 @@ namespace Microsoft.Windows.Controls.Primitives
}
}
private void SyncTextAndValueProperties(DependencyProperty p, string text)
protected void SyncTextAndValueProperties(DependencyProperty p, string text)
{
//prevents recursive syncing properties
if (_isSyncingTextAndValueProperties)

147
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/DateTimeUpDown/Implementation/DateTimeUpDown.cs

@ -8,14 +8,13 @@ using System.Windows.Data;
namespace Microsoft.Windows.Controls
{
public class DateTimeUpDown : UpDownBase
public class DateTimeUpDown : UpDownBase<DateTime?>
{
#region Members
private List<DateTimeInfo> _dateTimeInfoList = new List<DateTimeInfo>();
private DateTimeInfo _selectedDateTimeInfo;
private bool _fireSelectionChangedEvent = true;
private bool _isSyncingTextAndValueProperties;
private DateTimeParser _dateTimeParser;
@ -89,58 +88,6 @@ namespace Microsoft.Windows.Controls
#endregion //FormatString
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(DateTime?), typeof(DateTimeUpDown), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, OnCoerceValue));
public DateTime? Value
{
get { return (DateTime?)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private static object OnCoerceValue(DependencyObject o, object value)
{
DateTimeUpDown dateTimeUpDown = o as DateTimeUpDown;
if (dateTimeUpDown != null)
return dateTimeUpDown.OnCoerceValue((DateTime?)value);
else
return value;
}
protected virtual DateTime? OnCoerceValue(DateTime? value)
{
//if the user entered a string value to represent a date or time, we need to parse that string into a valid DatTime value
if (value != null && !(value is DateTime))
{
return DateTime.Parse(value.ToString(), DateTimeFormatInfo);
}
return value;
}
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
DateTimeUpDown dateTimeUpDown = o as DateTimeUpDown;
if (dateTimeUpDown != null)
dateTimeUpDown.OnValueChanged((DateTime?)e.OldValue, (DateTime?)e.NewValue);
}
protected virtual void OnValueChanged(DateTime? oldValue, DateTime? newValue)
{
//whenever the value changes we need to parse out the value into out DateTimeInfo segments so we can keep track of the individual pieces
//but only if it is not null
if (newValue != null)
ParseValueIntoDateTimeInfo();
SyncTextAndValueProperties(DateTimeUpDown.ValueProperty, newValue);
RoutedPropertyChangedEventArgs<DateTime?> args = new RoutedPropertyChangedEventArgs<DateTime?>(oldValue, newValue);
args.RoutedEvent = DateTimeUpDown.ValueChangedEvent;
RaiseEvent(args);
}
#endregion //Value
#endregion //Properties
#region Constructors
@ -152,7 +99,7 @@ namespace Microsoft.Windows.Controls
public DateTimeUpDown()
{
DateTimeFormatInfo = DateTimeFormatInfo.GetInstance(CultureInfo.CurrentCulture);
DateTimeFormatInfo = DateTimeFormatInfo.GetInstance(CultureInfo);
InitializeDateTimeInfoList();
}
@ -194,6 +141,7 @@ namespace Microsoft.Windows.Controls
BindingExpression binding = BindingOperations.GetBindingExpression(TextBox, System.Windows.Controls.TextBox.TextProperty);
binding.UpdateSource();
_fireSelectionChangedEvent = true;
e.Handled = true;
}
return;
}
@ -210,7 +158,6 @@ namespace Microsoft.Windows.Controls
protected override void OnTextChanged(string previousValue, string currentValue)
{
//TODO: clean this up and make sure it doesn't fire recursively
if (String.IsNullOrEmpty(currentValue))
{
Value = null;
@ -224,7 +171,44 @@ namespace Microsoft.Windows.Controls
DateTime result;
var success = _dateTimeParser.TryParse(currentValue, out result, current);
SyncTextAndValueProperties(InputBase.TextProperty, result);
SyncTextAndValueProperties(InputBase.TextProperty, result.ToString());
}
protected override DateTime? OnCoerceValue(DateTime? value)
{
//if the user entered a string value to represent a date or time, we need to parse that string into a valid DatTime value
if (value != null && !(value is DateTime))
{
return DateTime.Parse(value.ToString(), DateTimeFormatInfo);
}
return value;
}
protected override DateTime? ConvertTextToValue(string text)
{
if (string.IsNullOrEmpty(text))
return null;
return DateTime.Parse(text, CultureInfo.CurrentCulture);
}
protected override string ConvertValueToText()
{
if (Value == null) return string.Empty;
DateTime dt = DateTime.Parse(Value.ToString(), CultureInfo);
return dt.ToString(GetFormatString(Format), CultureInfo);
}
protected override void OnValueChanged(DateTime? oldValue, DateTime? newValue)
{
//whenever the value changes we need to parse out the value into out DateTimeInfo segments so we can keep track of the individual pieces
//but only if it is not null
if (newValue != null)
ParseValueIntoDateTimeInfo();
base.OnValueChanged(oldValue, newValue);
}
#endregion //Base Class Overrides
@ -233,7 +217,7 @@ namespace Microsoft.Windows.Controls
void TextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
if (_fireSelectionChangedEvent)
if (_fireSelectionChangedEvent)
PerformMouseSelection();
else
_fireSelectionChangedEvent = true;
@ -241,17 +225,6 @@ namespace Microsoft.Windows.Controls
#endregion //Event Hanlders
#region Events
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<DateTime?>), typeof(DateTimeUpDown));
public event RoutedPropertyChangedEventHandler<DateTime?> ValueChanged
{
add { AddHandler(ValueChangedEvent, value); }
remove { RemoveHandler(ValueChangedEvent, value); }
}
#endregion //Events
#region Methods
private void InitializeDateTimeInfoListAndParseValue()
@ -564,42 +537,6 @@ namespace Microsoft.Windows.Controls
_fireSelectionChangedEvent = true;
}
private DateTime? ConvertTextToValue(string text)
{
if (string.IsNullOrEmpty(text))
return null;
return DateTime.Parse(text, CultureInfo.CurrentCulture);
}
private string ConvertValueToText(object value)
{
if (value == null) return string.Empty;
DateTime dt = DateTime.Parse(value.ToString(), CultureInfo.CurrentCulture);
return dt.ToString(GetFormatString(Format), CultureInfo.CurrentCulture);
}
private void SyncTextAndValueProperties(DependencyProperty p, object newValue)
{
//prevents recursive syncing properties
if (_isSyncingTextAndValueProperties)
return;
_isSyncingTextAndValueProperties = true;
//this only occures when the user typed in the value
if (InputBase.TextProperty == p)
{
string text = newValue == null ? String.Empty : newValue.ToString();
SetValue(DateTimeUpDown.ValueProperty, ConvertTextToValue(text));
}
SetValue(InputBase.TextProperty, ConvertValueToText(newValue));
_isSyncingTextAndValueProperties = false;
}
#endregion //Methods
}
}

359
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/Implementation/NumericUpDown.cs

@ -1,369 +1,10 @@
using System;
using System.Windows;
using System.Globalization;
using System.Windows.Input;
using Microsoft.Windows.Controls.Primitives;
namespace Microsoft.Windows.Controls
{
[Obsolete("This control has been replaced with numeric data type specific controls; DecimalUpDown, DoubleUpDown, IntegerUpDown")]
public class NumericUpDown : UpDownBase
{
#region Members
/// <summary>
/// Flags if the Text and Value properties are in the process of being sync'd
/// </summary>
private bool _isSyncingTextAndValueProperties;
#endregion //Members
#region Properties
#region DefaultValue
public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(decimal), typeof(NumericUpDown), new UIPropertyMetadata(default(decimal)));
public decimal DefaultValue
{
get { return (decimal)GetValue(DefaultValueProperty); }
set { SetValue(DefaultValueProperty, value); }
}
#endregion //DefaultValue
#region Minimum
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(decimal), typeof(NumericUpDown), new PropertyMetadata(Decimal.MinValue, OnMinimumPropertyChanged));
public decimal Minimum
{
get { return (decimal)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
private static void OnMinimumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NumericUpDown nud = d as NumericUpDown;
nud.SetValidSpinDirection();
}
#endregion Minimum
#region Maximum
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(decimal), typeof(NumericUpDown), new PropertyMetadata(Decimal.MaxValue, OnMaximumPropertyChanged));
public decimal Maximum
{
get { return (decimal)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
private static void OnMaximumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NumericUpDown nud = d as NumericUpDown;
nud.SetValidSpinDirection();
}
#endregion Maximum
#region Increment
public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(decimal), typeof(NumericUpDown), new PropertyMetadata(1M));
public decimal Increment
{
get { return (decimal)GetValue(IncrementProperty); }
set { SetValue(IncrementProperty, value); }
}
#endregion
#region FormatString
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); }
set { SetValue(StringFormatProperty, value); }
}
private static void OnStringFormatPropertyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NumericUpDown nud = d as NumericUpDown;
nud.OnStringFormatChanged(e.OldValue.ToString(), e.NewValue.ToString());
}
protected virtual void OnStringFormatChanged(string oldValue, string newValue)
{
//Don't think this is needed anymore
//SyncTextAndValueProperties(NumericUpDown.TextProperty, Value);
}
#endregion //FormatString
#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
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(decimal?), typeof(NumericUpDown), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, OnCoerceValue));
public decimal? Value
{
get { return (decimal?)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private static object OnCoerceValue(DependencyObject o, object value)
{
NumericUpDown numericUpDown = o as NumericUpDown;
if (numericUpDown != null)
return numericUpDown.OnCoerceValue((decimal?)value);
else
return value;
}
protected virtual decimal? OnCoerceValue(decimal? value)
{
if (value == null) return value;
decimal val = value.Value;
if (val < Minimum)
{
return Minimum;
}
else if (val > Maximum)
{
return Maximum;
}
else
{
return value;
}
}
private static void OnValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
NumericUpDown numericUpDown = o as NumericUpDown;
if (numericUpDown != null)
numericUpDown.OnValueChanged((decimal?)e.OldValue, (decimal?)e.NewValue);
}
protected virtual void OnValueChanged(decimal? oldValue, decimal? newValue)
{
SetValidSpinDirection();
SyncTextAndValueProperties(NumericUpDown.ValueProperty, newValue);
RoutedPropertyChangedEventArgs<decimal?> args = new RoutedPropertyChangedEventArgs<decimal?>(oldValue, newValue);
args.RoutedEvent = NumericUpDown.ValueChangedEvent;
RaiseEvent(args);
}
#endregion //Value
#endregion
#region Constructors
static NumericUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), new FrameworkPropertyMetadata(typeof(NumericUpDown)));
}
#endregion //Constructors
#region Base Class Overrides
protected override void OnAccessKey(AccessKeyEventArgs e)
{
if (TextBox != null)
TextBox.Focus();
base.OnAccessKey(e);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
SetValidSpinDirection();
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;
}
}
protected override void OnGotFocus(RoutedEventArgs e)
{
if (TextBox != null)
TextBox.Focus();
}
protected override void OnIncrement()
{
if (Value.HasValue)
Value += Increment;
else
Value = DefaultValue;
}
protected override void OnDecrement()
{
if (Value.HasValue)
Value -= Increment;
else
Value = DefaultValue;
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.Key == Key.Enter)
{
if (IsEditable)
SyncTextAndValueProperties(InputBase.TextProperty, TextBox.Text);
}
}
protected override void OnTextChanged(string previousValue, string currentValue)
{
SyncTextAndValueProperties(InputBase.TextProperty, currentValue);
}
#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 Events
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, typeof(RoutedPropertyChangedEventHandler<decimal?>), typeof(NumericUpDown));
public event RoutedPropertyChangedEventHandler<decimal?> ValueChanged
{
add { AddHandler(ValueChangedEvent, value); }
remove { RemoveHandler(ValueChangedEvent, value); }
}
#endregion //Events
#region Methods
private decimal? ConvertTextToValue(string text)
{
decimal? result = null;
if (String.IsNullOrEmpty(text))
return result;
NumberFormatInfo info = NumberFormatInfo.GetInstance(CultureInfo.CurrentCulture);
try
{
result = FormatString.Contains("P") ? ParsePercent(text, info) : ParseDecimal(text, info);
}
catch
{
Text = ConvertValueToText(Value);
return Value;
}
return result;
}
private string ConvertValueToText(object value)
{
if (!Value.HasValue)
return String.Empty;
return Value.Value.ToString(FormatString, CultureInfo.CurrentCulture);
}
private void SyncTextAndValueProperties(DependencyProperty p, object newValue)
{
//prevents recursive syncing properties
if (_isSyncingTextAndValueProperties)
return;
_isSyncingTextAndValueProperties = true;
//this only occures when the user typed in the value
if (InputBase.TextProperty == p)
{
string text = newValue == null ? String.Empty : newValue.ToString();
SetValue(NumericUpDown.ValueProperty, ConvertTextToValue(text));
}
SetValue(InputBase.TextProperty, ConvertValueToText(newValue));
_isSyncingTextAndValueProperties = false;
}
private static decimal ParseDecimal(string text, NumberFormatInfo info)
{
return decimal.Parse(text, NumberStyles.Any, info);
}
private static decimal ParsePercent(string text, NumberFormatInfo info)
{
text = text.Replace(info.PercentSymbol, null);
decimal result = decimal.Parse(text, NumberStyles.Any, info);
result = result / 100;
return result;
}
/// <summary>
/// Sets the valid spin direction based on current value, minimum and maximum.
/// </summary>
private void SetValidSpinDirection()
{
ValidSpinDirections validDirections = ValidSpinDirections.None;
if (Convert.ToDecimal(Value) < Maximum)
{
validDirections = validDirections | ValidSpinDirections.Increase;
}
if (Convert.ToDecimal(Value) > Minimum)
{
validDirections = validDirections | ValidSpinDirections.Decrease;
}
if (Spinner != null)
{
Spinner.ValidSpinDirection = validDirections;
}
}
#endregion //Methods
}
public abstract class NumericUpDown<T> : UpDownBase<T>
{
#region Properties

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

@ -124,42 +124,4 @@
</Setter>
</Style>
<!-- =============================================================================== -->
<!-- NumericUpDown -->
<!-- =============================================================================== -->
<Style TargetType="{x:Type local:NumericUpDown}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="WatermarkTemplate" Value="{StaticResource DefaultWatermarkTemplate}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NumericUpDown}">
<local:ButtonSpinner x:Name="Spinner" IsTabStop="False" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}"
AllowSpin="{TemplateBinding AllowSpin}" ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}">
<local:WatermarkTextBox x:Name="TextBox" BorderThickness="0"
Background="{TemplateBinding Background}"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontStretch="{TemplateBinding FontStretch}"
FontStyle="{TemplateBinding FontStyle}"
FontWeight="{TemplateBinding FontWeight}"
Foreground="{TemplateBinding Foreground}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
IsReadOnly="{Binding IsEditable, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource InverseBoolConverter}}"
MinWidth="20" AcceptsReturn="False"
TextWrapping="NoWrap"
TabIndex="{TemplateBinding TabIndex}"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}"
Watermark="{TemplateBinding Watermark}"
WatermarkTemplate="{TemplateBinding WatermarkTemplate}"/>
</local:ButtonSpinner>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
Loading…
Cancel
Save