Browse Source

added new NumericUpDown control. It provides spin buttons to increment and decrement the value. You can also specifiy a format in which to show the value such as currency C2, or decimal up to three decimals F3. YOu can specify a Min and Max value as well as the increment values. You can also specify if the user can type in the textbox by setting IsEditable property. Support for up/down arrows and mouse wheel.

<toolkit:NumericUpDown Value="25" FormatString="C2" Increment=".5" Maximum="30" Minimum="20" />
pull/1645/head
brianlagunas_cp 16 years ago
parent
commit
532dab48f0
  1. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/ButtonSpinner.cs
  2. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/SpinDirection.cs
  3. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/SpinEventArgs.cs
  4. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/Spinner.cs
  5. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/ValidSpinDirections.cs
  6. 163
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/NumericUpDown.cs
  7. 113
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml
  8. 331
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/UpDownBase/UpDownBase.cs
  9. 11
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/ButtonSpinner.cs

@ -3,7 +3,6 @@ using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Controls.Primitives;
using Microsoft.Windows.Controls.Primitives;
namespace Microsoft.Windows.Controls
{

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/SpinDirection.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/SpinDirection.cs

@ -1,6 +1,6 @@
using System;
namespace Microsoft.Windows.Controls.Primitives
namespace Microsoft.Windows.Controls
{
/// <summary>
/// Represents spin directions that could be initiated by the end-user.

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/SpinEventArgs.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/SpinEventArgs.cs

@ -1,7 +1,7 @@
using System;
using System.Windows;
namespace Microsoft.Windows.Controls.Primitives
namespace Microsoft.Windows.Controls
{
/// <summary>
/// Provides data for the Spinner.Spin event.

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/Spinner.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/Spinner.cs

@ -2,7 +2,7 @@
using System.Windows.Controls;
using System.Windows;
namespace Microsoft.Windows.Controls.Primitives
namespace Microsoft.Windows.Controls
{
/// <summary>
/// Base class for controls that represents controls that can spin.

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Primitives/ValidSpinDirections.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ButtonSpinner/ValidSpinDirections.cs

@ -1,6 +1,6 @@
using System;
namespace Microsoft.Windows.Controls.Primitives
namespace Microsoft.Windows.Controls
{
/// <summary>
/// Represents spin directions that are valid.

163
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/NumericUpDown/NumericUpDown.cs

@ -0,0 +1,163 @@
using System;
using System.Windows;
using System.Globalization;
namespace Microsoft.Windows.Controls
{
public class NumericUpDown : UpDownBase<double>
{
#region Properties
#region Minimum
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), typeof(NumericUpDown), new PropertyMetadata(0d, OnMinimumPropertyChanged));
public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
private static void OnMinimumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
protected virtual void OnMinimumChanged(double oldValue, double newValue)
{
}
#endregion Minimum
#region Maximum
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(NumericUpDown), new PropertyMetadata(100d, OnMaximumPropertyChanged));
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
private static void OnMaximumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
protected virtual void OnMaximumChanged(double oldValue, double newValue)
{
}
#endregion Maximum
#region Increment
public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(double), typeof(NumericUpDown), new PropertyMetadata(1d, OnIncrementPropertyChanged));
public double Increment
{
get { return (double)GetValue(IncrementProperty); }
set { SetValue(IncrementProperty, value); }
}
private static void OnIncrementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
protected virtual void OnIncrementChanged(double oldValue, double newValue)
{
}
#endregion
#region FormatString
public static readonly DependencyProperty StringFormatProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(NumericUpDown), new PropertyMetadata("F0", 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)
{
Text = FormatValue();
}
#endregion //FormatString
#endregion
#region Constructors
public NumericUpDown()
: base()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), new FrameworkPropertyMetadata(typeof(NumericUpDown)));
}
#endregion //Constructors
#region Base Class Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
SetValidSpinDirection();
}
protected override void OnValueChanged(RoutedPropertyChangedEventArgs<double> e)
{
SetValidSpinDirection();
}
protected override double ParseValue(string text)
{
return double.Parse(text, NumberStyles.Any, CultureInfo.CurrentCulture);
}
protected internal override string FormatValue()
{
return Value.ToString(FormatString, CultureInfo.CurrentCulture);
}
protected override void OnIncrement()
{
Value = (double)((decimal)Value + (decimal)Increment);
}
protected override void OnDecrement()
{
Value = (double)((decimal)Value - (decimal)Increment);
}
#endregion //Base Class Overrides
#region Methods
/// <summary>
/// Sets the valid spin direction based on current value, minimum and maximum.
/// </summary>
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
}
}

113
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -930,16 +930,18 @@
<!-- ButtonSpinner -->
<!-- =============================================================================== -->
<SolidColorBrush x:Key="SpinButtonGlyphNormalForegroundFillKey" Color="#FF000000" />
<DataTemplate x:Key="IncreaseGlyph">
<Path Width="7" Height="4" Data="M 0,3 C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,2 5,1 5,1 5,1 4,1 4,1 4,1 4,0 4,0 4,0 3,0 3,0 3,0 3,1 3,1 3,1 2,1 2,1 2,1 2,2 2,2 2,2 1,2 1,2 1,2 1,3 1,3 1,3 0,3 0,3 z" Fill="#FF000000"/>
<Path Width="7" Height="4" Data="M 0,3 C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,2 5,1 5,1 5,1 4,1 4,1 4,1 4,0 4,0 4,0 3,0 3,0 3,0 3,1 3,1 3,1 2,1 2,1 2,1 2,2 2,2 2,2 1,2 1,2 1,2 1,3 1,3 1,3 0,3 0,3 z" Fill="{StaticResource SpinButtonGlyphNormalForegroundFillKey}"/>
</DataTemplate>
<DataTemplate x:Key="DecreaseGlyph">
<Path Width="7" Height="4" Data="M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z" Fill="#FF000000"/>
<Path Width="7" Height="4" Data="M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z" Fill="{StaticResource SpinButtonGlyphNormalForegroundFillKey}"/>
</DataTemplate>
<SolidColorBrush x:Key="SpinButtonNormalOuterBorderFillKey" Color="#FFABADB3"/>
<LinearGradientBrush x:Key="SpinButtonNormalInnerBorderFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush x:Key="SpinButtonNormalInnerBorderFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="0" Color="#FFfcfcfc"/>
@ -947,9 +949,9 @@
<GradientStop Offset="0.69" Color="#FFf3f3f3"/>
<GradientStop Offset="1" Color="#FFf3f3f3"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="SpinButtonNormalCenterFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush x:Key="SpinButtonNormalCenterFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="0" Color="#FFf2f2f2"/>
@ -957,51 +959,51 @@
<GradientStop Offset="0.69" Color="#FFd1d1d1"/>
<GradientStop Offset="1" Color="#FFd1d1d1"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<SolidColorBrush x:Key="SpinButtonHottrackOuterBorderFillKey" Color="#FF3C7FB1"/>
<LinearGradientBrush x:Key="SpinButtonHottrackInnerBorderFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFfafdfe" Offset="0" />
<GradientStop Color="#FFf5fbfe" Offset="0.5" />
<GradientStop Color="#FFeff9fe" Offset="0.5009999871253967" />
<GradientStop Color="#FFe8f5fc" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
<LinearGradientBrush x:Key="SpinButtonHottrackInnerBorderFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFfafdfe" Offset="0" />
<GradientStop Color="#FFf5fbfe" Offset="0.5" />
<GradientStop Color="#FFeff9fe" Offset="0.5009999871253967" />
<GradientStop Color="#FFe8f5fc" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="SpinButtonHottrackCenterFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFeaf6fd" Offset="0" />
<GradientStop Color="#FFd9f0fc" Offset="0.5" />
<GradientStop Color="#FFbee6fd" Offset="0.5009999871253967" />
<GradientStop Color="#FFa7d9f5" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
<LinearGradientBrush x:Key="SpinButtonHottrackCenterFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFeaf6fd" Offset="0" />
<GradientStop Color="#FFd9f0fc" Offset="0.5" />
<GradientStop Color="#FFbee6fd" Offset="0.5009999871253967" />
<GradientStop Color="#FFa7d9f5" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<SolidColorBrush x:Key="SpinButtonPressedOuterBorderFillKey" Color="#FF2C628B"/>
<LinearGradientBrush x:Key="SpinButtonPressedInnerBorderFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF9eb0ba" Offset="0" />
<GradientStop Color="#FF9abacb" Offset="0.5" />
<GradientStop Color="#FF78aac5" Offset="0.5008999705314636" />
<GradientStop Color="#FF5a96b8" Offset="0.8999999761581421" />
<GradientStop Color="#FF68b2da" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
<LinearGradientBrush x:Key="SpinButtonPressedInnerBorderFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF9eb0ba" Offset="0" />
<GradientStop Color="#FF9abacb" Offset="0.5" />
<GradientStop Color="#FF78aac5" Offset="0.5008999705314636" />
<GradientStop Color="#FF5a96b8" Offset="0.8999999761581421" />
<GradientStop Color="#FF68b2da" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="SpinButtonPressedCenterFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFe5f4fc" Offset="0" />
<GradientStop Color="#FFc4e5f6" Offset="0.5" />
<GradientStop Color="#FF98d1ef" Offset="0.5009999871253967" />
<GradientStop Color="#FF68b3db" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
<LinearGradientBrush x:Key="SpinButtonPressedCenterFillKey" StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFe5f4fc" Offset="0" />
<GradientStop Color="#FFc4e5f6" Offset="0.5" />
<GradientStop Color="#FF98d1ef" Offset="0.5009999871253967" />
<GradientStop Color="#FF68b3db" Offset="1" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="SpinButtonStyle" TargetType="{x:Type RepeatButton}">
@ -1079,4 +1081,29 @@
</Setter>
</Style>
<!-- =============================================================================== -->
<!-- NumericUpDown -->
<!-- =============================================================================== -->
<Style TargetType="{x:Type local:NumericUpDown}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:NumericUpDown}">
<local:ButtonSpinner x:Name="Spinner">
<TextBox x:Name="Text" BorderThickness="0"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontStretch="{TemplateBinding FontStretch}"
FontStyle="{TemplateBinding FontStyle}"
FontWeight="{TemplateBinding FontWeight}"
Foreground="{TemplateBinding Foreground}"
MinWidth="20" AcceptsReturn="False"
TextAlignment="Right" TextWrapping="NoWrap"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" />
</local:ButtonSpinner>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

331
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/UpDownBase/UpDownBase.cs

@ -0,0 +1,331 @@
using System;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows;
namespace Microsoft.Windows.Controls
{
public abstract class UpDownBase<T> : Control
{
#region Members
/// <summary>
/// Name constant for Text template part.
/// </summary>
internal const string ElementTextName = "Text";
/// <summary>
/// Name constant for Spinner template part.
/// </summary>
internal const string ElementSpinnerName = "Spinner";
/// <summary>
/// Flags if the Text and Value properties are in the process of being sync'd
/// </summary>
bool _isSyncingTextAndValueProperties;
#endregion //Members
#region Properties
#region Value
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(T), typeof(UpDownBase<T>), new FrameworkPropertyMetadata(default(T), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValuePropertyChanged));
public virtual T Value
{
get { return (T)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
UpDownBase<T> udb = (UpDownBase<T>)d;
T oldValue = (T)e.OldValue;
T newValue = (T)e.NewValue;
udb.SyncTextAndValueProperties(e.Property, e.NewValue);
RoutedPropertyChangedEventArgs<T> changedArgs = new RoutedPropertyChangedEventArgs<T>(oldValue, newValue);
udb.OnValueChanged(changedArgs);
}
protected virtual void OnValueChanged(RoutedPropertyChangedEventArgs<T> e)
{
if (ValueChanged != null)
ValueChanged(this, e);
}
#endregion //Value
#region Text
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UpDownBase<T>), new FrameworkPropertyMetadata("0", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnTextPropertyChanged));
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
NumericUpDown nud = (NumericUpDown)d;
nud.SyncTextAndValueProperties(e.Property, e.NewValue);
}
protected virtual void OnTextChanged(string oldValue, string newValue)
{
}
#endregion //Text
#region IsEditable
public static readonly DependencyProperty IsEditableProperty = DependencyProperty.Register("IsEditable", typeof(bool), typeof(UpDownBase<T>), new PropertyMetadata(true, OnIsEditablePropertyChanged));
public bool IsEditable
{
get { return (bool)GetValue(IsEditableProperty); }
set { SetValue(IsEditableProperty, value); }
}
private static void OnIsEditablePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
UpDownBase<T> source = d as UpDownBase<T>;
source.OnIsEditableChanged((bool)e.OldValue, (bool)e.NewValue);
}
protected virtual void OnIsEditableChanged(bool oldValue, bool newValue)
{
if (TextBox != null)
TextBox.IsReadOnly = !IsEditable;
}
#endregion //IsEditable
internal TextBox TextBox { get; private set; }
private Spinner _spinner;
internal Spinner Spinner
{
get { return _spinner; }
private set
{
if (_spinner != null)
{
_spinner.Spin -= OnSpinnerSpin;
}
_spinner = value;
if (_spinner != null)
{
_spinner.Spin += OnSpinnerSpin;
}
}
}
#endregion //Properties
#region Constructors
protected UpDownBase()
{
}
#endregion //Constructors
#region Base Class Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
TextBox = GetTemplateChild(ElementTextName) as TextBox;
Spinner = GetTemplateChild(ElementSpinnerName) as Spinner;
if (TextBox != null)
TextBox.IsReadOnly = !IsEditable;
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
switch (e.Key)
{
case Key.Up:
{
DoIncrement();
e.Handled = true;
break;
}
case Key.Down:
{
DoDecrement();
e.Handled = true;
break;
}
}
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
if (!e.Handled)
{
if (e.Delta < 0)
{
DoDecrement();
}
else if (0 < e.Delta)
{
DoIncrement();
}
e.Handled = true;
}
}
#endregion //Base Class Overrides
#region Methods
#region Abstract
/// <summary>
/// Called by ApplyValue to parse user input.
/// </summary>
/// <param name="text">User input.</param>
/// <returns>Value parsed from user input.</returns>
protected abstract T ParseValue(string text);
/// <summary>
/// Renders the value property into the textbox text.
/// </summary>
/// <returns>Formatted Value.</returns>
protected internal abstract string FormatValue();
/// <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
#region Protected
/// <summary>
/// GetValue override to return Value property as object type.
/// </summary>
/// <returns>The Value property as object type.</returns>
protected object GetValue()
{
return Value;
}
/// <summary>
/// SetValue override to set value to Value property.
/// </summary>
/// <param name="value">New value.</param>
protected void SetValue(object value)
{
Value = (T)value;
}
#endregion //Protected
#region Private
/// <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();
}
}
private void SyncTextAndValueProperties(DependencyProperty p, object newValue)
{
//prevents recursive syncing properties
if (_isSyncingTextAndValueProperties)
return;
_isSyncingTextAndValueProperties = true;
if (NumericUpDown.ValueProperty == p)
{
SetValue(NumericUpDown.TextProperty, FormatValue());
}
else if (NumericUpDown.TextProperty == p)
{
SetValue(NumericUpDown.ValueProperty, ParseValue(newValue.ToString()));
}
_isSyncingTextAndValueProperties = false;
}
#endregion //Private
#region Virtual
/// <summary>
/// Occurs when the spinner spins.
/// </summary>
/// <param name="e">Event args.</param>
protected virtual void OnSpin(SpinEventArgs e)
{
if (e == null)
throw new ArgumentNullException("e");
if (e.Direction == SpinDirection.Increase)
DoIncrement();
else
DoDecrement();
}
#endregion //Virtual
#endregion //Methods
#region Event Handlers
/// <summary>
/// Event handler for Spinner template part's Spin event.
/// </summary>
/// <param name="sender">The Spinner template part.</param>
/// <param name="e">Event args.</param>
private void OnSpinnerSpin(object sender, SpinEventArgs e)
{
OnSpin(e);
}
#endregion //Event Handlers
#region Events
/// <summary>
/// Occurs when Value property has changed.
/// </summary>
public event RoutedPropertyChangedEventHandler<T> ValueChanged;
#endregion //Events
}
}

11
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -72,11 +72,12 @@
<Compile Include="ColorPicker\HsvColor.cs" />
<Compile Include="ColorPicker\ColorUtilities.cs" />
<Compile Include="ColorPicker\ColorSpectrumSlider.cs" />
<Compile Include="Core\Primitives\SpinDirection.cs" />
<Compile Include="Core\Primitives\SpinEventArgs.cs" />
<Compile Include="Core\Primitives\Spinner.cs" />
<Compile Include="Core\Primitives\ValidSpinDirections.cs" />
<Compile Include="ButtonSpinner\SpinDirection.cs" />
<Compile Include="ButtonSpinner\SpinEventArgs.cs" />
<Compile Include="ButtonSpinner\Spinner.cs" />
<Compile Include="ButtonSpinner\ValidSpinDirections.cs" />
<Compile Include="MessageBox\MessageBox.cs" />
<Compile Include="NumericUpDown\NumericUpDown.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
@ -102,6 +103,7 @@
<Compile Include="RichTextBox\Formatters\RtfFormatter.cs" />
<Compile Include="RichTextBox\Formatters\XamlFormatter.cs" />
<Compile Include="RichTextBox\RichTextBox.cs" />
<Compile Include="UpDownBase\UpDownBase.cs" />
<Compile Include="VisualStates.cs" />
<Compile Include="MessageBox\VisualStates.MessageBox.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
@ -142,6 +144,7 @@
<Resource Include="RichTextBoxFormatBar\Images\Underline16.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Core\Primitives\" />
<Folder Include="RichTextBox\FormatToolbar\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

Loading…
Cancel
Save