Init
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
[Flags]
|
||||
public enum AllowedSpecialValues
|
||||
{
|
||||
None = 0,
|
||||
NaN = 1,
|
||||
PositiveInfinity = 2,
|
||||
NegativeInfinity = 4,
|
||||
AnyInfinity = PositiveInfinity | NegativeInfinity,
|
||||
Any = NaN | AnyInfinity
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class ByteUpDown : CommonNumericUpDown<byte>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static ByteUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( ByteUpDown ), ( byte )1, byte.MinValue, byte.MaxValue );
|
||||
}
|
||||
|
||||
public ByteUpDown()
|
||||
: base( Byte.TryParse, Decimal.ToByte, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override byte IncrementValue( byte value, byte increment )
|
||||
{
|
||||
return ( byte )( value + increment );
|
||||
}
|
||||
|
||||
protected override byte DecrementValue( byte value, byte increment )
|
||||
{
|
||||
return ( byte )( value - increment );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public abstract class CommonNumericUpDown<T> : NumericUpDown<T?> where T : struct, IFormattable, IComparable<T>
|
||||
{
|
||||
protected delegate bool FromText( string s, NumberStyles style, IFormatProvider provider, out T result );
|
||||
protected delegate T FromDecimal( decimal d );
|
||||
|
||||
private FromText _fromText;
|
||||
private FromDecimal _fromDecimal;
|
||||
private Func<T, T, bool> _fromLowerThan;
|
||||
private Func<T, T, bool> _fromGreaterThan;
|
||||
|
||||
|
||||
#region ParsingNumberStyle
|
||||
|
||||
public static readonly DependencyProperty ParsingNumberStyleProperty =
|
||||
DependencyProperty.Register( "ParsingNumberStyle", typeof( NumberStyles ), typeof( CommonNumericUpDown<T> ), new UIPropertyMetadata( NumberStyles.Any ) );
|
||||
|
||||
public NumberStyles ParsingNumberStyle
|
||||
{
|
||||
get { return ( NumberStyles )GetValue( ParsingNumberStyleProperty ); }
|
||||
set { SetValue( ParsingNumberStyleProperty, value ); }
|
||||
}
|
||||
|
||||
#endregion //ParsingNumberStyle
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected CommonNumericUpDown( FromText fromText, FromDecimal fromDecimal, Func<T, T, bool> fromLowerThan, Func<T, T, bool> fromGreaterThan )
|
||||
{
|
||||
if( fromText == null )
|
||||
throw new ArgumentNullException( "tryParseMethod" );
|
||||
|
||||
if( fromDecimal == null )
|
||||
throw new ArgumentNullException( "fromDecimal" );
|
||||
|
||||
if( fromLowerThan == null )
|
||||
throw new ArgumentNullException( "fromLowerThan" );
|
||||
|
||||
if( fromGreaterThan == null )
|
||||
throw new ArgumentNullException( "fromGreaterThan" );
|
||||
|
||||
_fromText = fromText;
|
||||
_fromDecimal = fromDecimal;
|
||||
_fromLowerThan = fromLowerThan;
|
||||
_fromGreaterThan = fromGreaterThan;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected static void UpdateMetadata( Type type, T? increment, T? minValue, T? maxValue )
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( type ) );
|
||||
UpdateMetadataCommon( type, increment, minValue, maxValue );
|
||||
}
|
||||
|
||||
private static void UpdateMetadataCommon( Type type, T? increment, T? minValue, T? maxValue )
|
||||
{
|
||||
IncrementProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( increment ) );
|
||||
MaximumProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( maxValue ) );
|
||||
MinimumProperty.OverrideMetadata( type, new FrameworkPropertyMetadata( minValue ) );
|
||||
}
|
||||
|
||||
protected void TestInputSpecialValue( AllowedSpecialValues allowedValues, AllowedSpecialValues valueToCompare )
|
||||
{
|
||||
if( ( allowedValues & valueToCompare ) != valueToCompare )
|
||||
{
|
||||
switch( valueToCompare )
|
||||
{
|
||||
case AllowedSpecialValues.NaN :
|
||||
throw new InvalidDataException( "Value to parse shouldn't be NaN." );
|
||||
case AllowedSpecialValues.PositiveInfinity:
|
||||
throw new InvalidDataException( "Value to parse shouldn't be Positive Infinity." );
|
||||
case AllowedSpecialValues.NegativeInfinity:
|
||||
throw new InvalidDataException( "Value to parse shouldn't be Negative Infinity." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsLowerThan( T? value1, T? value2 )
|
||||
{
|
||||
if( value1 == null || value2 == null )
|
||||
return false;
|
||||
|
||||
return _fromLowerThan( value1.Value, value2.Value );
|
||||
}
|
||||
|
||||
private bool IsGreaterThan( T? value1, T? value2 )
|
||||
{
|
||||
if( value1 == null || value2 == null )
|
||||
return false;
|
||||
|
||||
return _fromGreaterThan( value1.Value, value2.Value );
|
||||
}
|
||||
|
||||
private bool HandleNullSpin()
|
||||
{
|
||||
if( !Value.HasValue )
|
||||
{
|
||||
T forcedValue = ( DefaultValue.HasValue )
|
||||
? DefaultValue.Value
|
||||
: default( T );
|
||||
|
||||
Value = CoerceValueMinMax( forcedValue );
|
||||
|
||||
return true;
|
||||
}
|
||||
else if( !Increment.HasValue )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
internal bool IsValid( T? value )
|
||||
{
|
||||
return !IsLowerThan( value, Minimum ) && !IsGreaterThan( value, Maximum );
|
||||
}
|
||||
|
||||
private T? CoerceValueMinMax( T value )
|
||||
{
|
||||
if( IsLowerThan( value, Minimum ) )
|
||||
return Minimum;
|
||||
else if( IsGreaterThan( value, Maximum ) )
|
||||
return Maximum;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override void OnIncrement()
|
||||
{
|
||||
if( !HandleNullSpin() )
|
||||
{
|
||||
// if UpdateValueOnEnterKey is true,
|
||||
// Sync Value on Text only when Enter Key is pressed.
|
||||
if( this.UpdateValueOnEnterKey )
|
||||
{
|
||||
var currentValue = this.ConvertTextToValue( this.TextBox.Text );
|
||||
var result = this.IncrementValue( currentValue.Value, Increment.Value );
|
||||
var newValue = this.CoerceValueMinMax( result );
|
||||
this.TextBox.Text = newValue.Value.ToString( this.FormatString, this.CultureInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = this.IncrementValue( Value.Value, Increment.Value );
|
||||
this.Value = this.CoerceValueMinMax( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDecrement()
|
||||
{
|
||||
if( !HandleNullSpin() )
|
||||
{
|
||||
// if UpdateValueOnEnterKey is true,
|
||||
// Sync Value on Text only when Enter Key is pressed.
|
||||
if( this.UpdateValueOnEnterKey )
|
||||
{
|
||||
var currentValue = this.ConvertTextToValue( this.TextBox.Text );
|
||||
var result = this.DecrementValue( currentValue.Value, Increment.Value );
|
||||
var newValue = this.CoerceValueMinMax( result );
|
||||
this.TextBox.Text = newValue.Value.ToString( this.FormatString, this.CultureInfo );
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = this.DecrementValue( Value.Value, Increment.Value );
|
||||
this.Value = this.CoerceValueMinMax( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMinimumChanged( T? oldValue, T? newValue )
|
||||
{
|
||||
base.OnMinimumChanged( oldValue, newValue );
|
||||
|
||||
if( this.Value.HasValue && this.ClipValueToMinMax )
|
||||
{
|
||||
this.Value = this.CoerceValueMinMax( this.Value.Value );
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMaximumChanged( T? oldValue, T? newValue )
|
||||
{
|
||||
base.OnMaximumChanged( oldValue, newValue );
|
||||
|
||||
if( this.Value.HasValue && this.ClipValueToMinMax )
|
||||
{
|
||||
this.Value = this.CoerceValueMinMax( this.Value.Value );
|
||||
}
|
||||
}
|
||||
|
||||
protected override T? ConvertTextToValue( string text )
|
||||
{
|
||||
T? result = null;
|
||||
|
||||
if( String.IsNullOrEmpty( text ) )
|
||||
return result;
|
||||
|
||||
// Since the conversion from Value to text using a FormartString may not be parsable,
|
||||
// we verify that the already existing text is not the exact same value.
|
||||
string currentValueText = ConvertValueToText();
|
||||
if( object.Equals( currentValueText, text ) )
|
||||
return this.Value;
|
||||
|
||||
result = this.ConvertTextToValueCore( currentValueText, text );
|
||||
|
||||
if( this.ClipValueToMinMax )
|
||||
{
|
||||
return this.GetClippedMinMaxValue( result );
|
||||
}
|
||||
|
||||
ValidateDefaultMinMax( result );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override string ConvertValueToText()
|
||||
{
|
||||
if( Value == null )
|
||||
return string.Empty;
|
||||
|
||||
//Manage FormatString of type "{}{0:N2} °" (in xaml) or "{0:N2} °" in code-behind.
|
||||
if( FormatString.Contains( "{0" ) )
|
||||
return string.Format( CultureInfo, FormatString, Value.Value );
|
||||
|
||||
return Value.Value.ToString( FormatString, CultureInfo );
|
||||
}
|
||||
|
||||
protected override void SetValidSpinDirection()
|
||||
{
|
||||
ValidSpinDirections validDirections = ValidSpinDirections.None;
|
||||
|
||||
// Null increment always prevents spin.
|
||||
if( (this.Increment != null) && !IsReadOnly )
|
||||
{
|
||||
if( IsLowerThan( Value, Maximum ) || !Value.HasValue || !Maximum.HasValue)
|
||||
validDirections = validDirections | ValidSpinDirections.Increase;
|
||||
|
||||
if( IsGreaterThan( Value, Minimum ) || !Value.HasValue || !Minimum.HasValue )
|
||||
validDirections = validDirections | ValidSpinDirections.Decrease;
|
||||
}
|
||||
|
||||
if( Spinner != null )
|
||||
Spinner.ValidSpinDirection = validDirections;
|
||||
}
|
||||
|
||||
private bool IsPercent( string stringToTest )
|
||||
{
|
||||
int PIndex = stringToTest.IndexOf( "P" );
|
||||
if( PIndex >= 0 )
|
||||
{
|
||||
//stringToTest contains a "P" between 2 "'", it's considered as text, not percent
|
||||
bool isText = (stringToTest.Substring( 0, PIndex ).Contains( "'" )
|
||||
&& stringToTest.Substring( PIndex, FormatString.Length - PIndex ).Contains( "'" ));
|
||||
|
||||
return !isText;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private T? ConvertTextToValueCore( string currentValueText, string text )
|
||||
{
|
||||
T? result;
|
||||
|
||||
if( this.IsPercent( this.FormatString ) )
|
||||
{
|
||||
result = _fromDecimal( ParsePercent( text, CultureInfo ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
T outputValue = new T();
|
||||
// Problem while converting new text
|
||||
if( !_fromText( text, this.ParsingNumberStyle, CultureInfo, out outputValue ) )
|
||||
{
|
||||
bool shouldThrow = true;
|
||||
|
||||
// case 164198: Throw when replacing only the digit part of 99° through UI.
|
||||
// Check if CurrentValueText is also failing => it also contains special characters. ex : 90°
|
||||
T currentValueTextOutputValue;
|
||||
if( !_fromText( currentValueText, this.ParsingNumberStyle, CultureInfo, out currentValueTextOutputValue ) )
|
||||
{
|
||||
// extract non-digit characters
|
||||
var currentValueTextSpecialCharacters = currentValueText.Where( c => !Char.IsDigit( c ) );
|
||||
var textSpecialCharacters = text.Where( c => !Char.IsDigit( c ) );
|
||||
// same non-digit characters on currentValueText and new text => remove them on new Text to parse it again.
|
||||
if( currentValueTextSpecialCharacters.Except( textSpecialCharacters ).ToList().Count == 0 )
|
||||
{
|
||||
foreach( var character in textSpecialCharacters )
|
||||
{
|
||||
text = text.Replace( character.ToString(), string.Empty );
|
||||
}
|
||||
// if without the special characters, parsing is good, do not throw
|
||||
if( _fromText( text, this.ParsingNumberStyle, CultureInfo, out outputValue ) )
|
||||
{
|
||||
shouldThrow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( shouldThrow )
|
||||
throw new InvalidDataException( "Input string was not in a correct format." );
|
||||
}
|
||||
result = outputValue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private T? GetClippedMinMaxValue( T? result )
|
||||
{
|
||||
if( this.IsGreaterThan( result, this.Maximum ) )
|
||||
return this.Maximum;
|
||||
else if( this.IsLowerThan( result, this.Minimum ) )
|
||||
return this.Minimum;
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ValidateDefaultMinMax( T? value )
|
||||
{
|
||||
// DefaultValue is always accepted.
|
||||
if( object.Equals( value, DefaultValue ) )
|
||||
return;
|
||||
|
||||
if( IsLowerThan( value, Minimum ) )
|
||||
throw new ArgumentOutOfRangeException( "Minimum", String.Format( "Value must be greater than MinValue of {0}", Minimum ) );
|
||||
else if( IsGreaterThan( value, Maximum ) )
|
||||
throw new ArgumentOutOfRangeException( "Maximum", String.Format( "Value must be less than MaxValue of {0}", Maximum ) );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
|
||||
|
||||
#region Abstract Methods
|
||||
|
||||
protected abstract T IncrementValue( T value, T increment );
|
||||
|
||||
protected abstract T DecrementValue( T value, T increment );
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class DecimalUpDown : CommonNumericUpDown<decimal>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static DecimalUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( DecimalUpDown ), 1m, decimal.MinValue, decimal.MaxValue );
|
||||
}
|
||||
|
||||
public DecimalUpDown()
|
||||
: base( Decimal.TryParse, ( d ) => d, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override decimal IncrementValue( decimal value, decimal increment )
|
||||
{
|
||||
return value + increment;
|
||||
}
|
||||
|
||||
protected override decimal DecrementValue( decimal value, decimal increment )
|
||||
{
|
||||
return value - increment;
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class DoubleUpDown : CommonNumericUpDown<double>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static DoubleUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( DoubleUpDown ), 1d, double.NegativeInfinity, double.PositiveInfinity );
|
||||
}
|
||||
|
||||
public DoubleUpDown()
|
||||
: base( Double.TryParse, Decimal.ToDouble, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
|
||||
#region AllowInputSpecialValues
|
||||
|
||||
public static readonly DependencyProperty AllowInputSpecialValuesProperty =
|
||||
DependencyProperty.Register( "AllowInputSpecialValues", typeof( AllowedSpecialValues ), typeof( DoubleUpDown ), new UIPropertyMetadata( AllowedSpecialValues.None ) );
|
||||
|
||||
public AllowedSpecialValues AllowInputSpecialValues
|
||||
{
|
||||
get { return ( AllowedSpecialValues )GetValue( AllowInputSpecialValuesProperty ); }
|
||||
set { SetValue( AllowInputSpecialValuesProperty, value ); }
|
||||
}
|
||||
|
||||
#endregion //AllowInputSpecialValues
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override double? OnCoerceIncrement( double? baseValue )
|
||||
{
|
||||
if( baseValue.HasValue && double.IsNaN( baseValue.Value ) )
|
||||
throw new ArgumentException( "NaN is invalid for Increment." );
|
||||
|
||||
return base.OnCoerceIncrement( baseValue );
|
||||
}
|
||||
|
||||
protected override double? OnCoerceMaximum( double? baseValue )
|
||||
{
|
||||
if( baseValue.HasValue && double.IsNaN( baseValue.Value ) )
|
||||
throw new ArgumentException( "NaN is invalid for Maximum." );
|
||||
|
||||
return base.OnCoerceMaximum( baseValue );
|
||||
}
|
||||
|
||||
protected override double? OnCoerceMinimum( double? baseValue )
|
||||
{
|
||||
if( baseValue.HasValue && double.IsNaN( baseValue.Value ) )
|
||||
throw new ArgumentException( "NaN is invalid for Minimum." );
|
||||
|
||||
return base.OnCoerceMinimum( baseValue );
|
||||
}
|
||||
|
||||
protected override double IncrementValue( double value, double increment )
|
||||
{
|
||||
return value + increment;
|
||||
}
|
||||
|
||||
protected override double DecrementValue( double value, double increment )
|
||||
{
|
||||
return value - increment;
|
||||
}
|
||||
|
||||
protected override void SetValidSpinDirection()
|
||||
{
|
||||
if( Value.HasValue && double.IsInfinity( Value.Value ) && ( Spinner != null ) )
|
||||
{
|
||||
Spinner.ValidSpinDirection = ValidSpinDirections.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.SetValidSpinDirection();
|
||||
}
|
||||
}
|
||||
|
||||
protected override double? ConvertTextToValue( string text )
|
||||
{
|
||||
double? result = base.ConvertTextToValue( text );
|
||||
if( result != null )
|
||||
{
|
||||
if( double.IsNaN( result.Value ) )
|
||||
TestInputSpecialValue( this.AllowInputSpecialValues, AllowedSpecialValues.NaN );
|
||||
else if( double.IsPositiveInfinity( result.Value ) )
|
||||
TestInputSpecialValue( this.AllowInputSpecialValues, AllowedSpecialValues.PositiveInfinity );
|
||||
else if( double.IsNegativeInfinity( result.Value ) )
|
||||
TestInputSpecialValue( this.AllowInputSpecialValues, AllowedSpecialValues.NegativeInfinity );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class IntegerUpDown : CommonNumericUpDown<int>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static IntegerUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( IntegerUpDown ), 1, int.MinValue, int.MaxValue );
|
||||
}
|
||||
|
||||
public IntegerUpDown()
|
||||
: base( Int32.TryParse, Decimal.ToInt32, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override int IncrementValue( int value, int increment )
|
||||
{
|
||||
return value + increment;
|
||||
}
|
||||
|
||||
protected override int DecrementValue( int value, int increment )
|
||||
{
|
||||
return value - increment;
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class LongUpDown : CommonNumericUpDown<long>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static LongUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( LongUpDown ), 1L, long.MinValue, long.MaxValue );
|
||||
}
|
||||
|
||||
public LongUpDown()
|
||||
: base( Int64.TryParse, Decimal.ToInt64, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override long IncrementValue( long value, long increment )
|
||||
{
|
||||
return value + increment;
|
||||
}
|
||||
|
||||
protected override long DecrementValue( long value, long increment )
|
||||
{
|
||||
return value - increment;
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public abstract class NumericUpDown<T> : UpDownBase<T>
|
||||
{
|
||||
#pragma warning disable 0618
|
||||
|
||||
#region Properties
|
||||
|
||||
#region AutoMoveFocus
|
||||
|
||||
public bool AutoMoveFocus
|
||||
{
|
||||
get
|
||||
{
|
||||
return ( bool )GetValue( AutoMoveFocusProperty );
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue( AutoMoveFocusProperty, value );
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AutoMoveFocusProperty =
|
||||
DependencyProperty.Register( "AutoMoveFocus", typeof( bool ), typeof( NumericUpDown<T> ), new UIPropertyMetadata( false ) );
|
||||
|
||||
#endregion AutoMoveFocus
|
||||
|
||||
#region AutoSelectBehavior
|
||||
|
||||
public AutoSelectBehavior AutoSelectBehavior
|
||||
{
|
||||
get
|
||||
{
|
||||
return ( AutoSelectBehavior )GetValue( AutoSelectBehaviorProperty );
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue( AutoSelectBehaviorProperty, value );
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty AutoSelectBehaviorProperty =
|
||||
DependencyProperty.Register( "AutoSelectBehavior", typeof( AutoSelectBehavior ), typeof( NumericUpDown<T> ),
|
||||
new UIPropertyMetadata( AutoSelectBehavior.OnFocus ) );
|
||||
|
||||
#endregion AutoSelectBehavior PROPERTY
|
||||
|
||||
#region FormatString
|
||||
|
||||
public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register( "FormatString", typeof( string ), typeof( NumericUpDown<T> ), new UIPropertyMetadata( String.Empty, OnFormatStringChanged ) );
|
||||
public string FormatString
|
||||
{
|
||||
get
|
||||
{
|
||||
return ( string )GetValue( FormatStringProperty );
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue( FormatStringProperty, value );
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnFormatStringChanged( DependencyObject o, DependencyPropertyChangedEventArgs e )
|
||||
{
|
||||
NumericUpDown<T> numericUpDown = o as NumericUpDown<T>;
|
||||
if( numericUpDown != null )
|
||||
numericUpDown.OnFormatStringChanged( ( string )e.OldValue, ( string )e.NewValue );
|
||||
}
|
||||
|
||||
protected virtual void OnFormatStringChanged( string oldValue, string newValue )
|
||||
{
|
||||
if( IsInitialized )
|
||||
{
|
||||
this.SyncTextAndValueProperties( false, null );
|
||||
}
|
||||
}
|
||||
|
||||
#endregion //FormatString
|
||||
|
||||
#region Increment
|
||||
|
||||
public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register( "Increment", typeof( T ), typeof( NumericUpDown<T> ), new PropertyMetadata( default( T ), OnIncrementChanged, OnCoerceIncrement ) );
|
||||
public T Increment
|
||||
{
|
||||
get
|
||||
{
|
||||
return ( T )GetValue( IncrementProperty );
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue( IncrementProperty, value );
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnIncrementChanged( DependencyObject o, DependencyPropertyChangedEventArgs e )
|
||||
{
|
||||
NumericUpDown<T> numericUpDown = o as NumericUpDown<T>;
|
||||
if( numericUpDown != null )
|
||||
numericUpDown.OnIncrementChanged( ( T )e.OldValue, ( T )e.NewValue );
|
||||
}
|
||||
|
||||
protected virtual void OnIncrementChanged( T oldValue, T newValue )
|
||||
{
|
||||
if( this.IsInitialized )
|
||||
{
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
}
|
||||
|
||||
private static object OnCoerceIncrement( DependencyObject d, object baseValue )
|
||||
{
|
||||
NumericUpDown<T> numericUpDown = d as NumericUpDown<T>;
|
||||
if( numericUpDown != null )
|
||||
return numericUpDown.OnCoerceIncrement( ( T )baseValue );
|
||||
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
protected virtual T OnCoerceIncrement( T baseValue )
|
||||
{
|
||||
return baseValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SelectAllOnGotFocus (Obsolete)
|
||||
|
||||
[Obsolete( "This property is obsolete and should no longer be used. Use NumericUpDown.AutoSelectBehavior instead." )]
|
||||
public static readonly DependencyProperty SelectAllOnGotFocusProperty = DependencyProperty.Register( "SelectAllOnGotFocus", typeof( bool ), typeof( NumericUpDown<T> ), new PropertyMetadata( true ) );
|
||||
[Obsolete( "This property is obsolete and should no longer be used. Use NumericUpDown.AutoSelectBehavior instead." )]
|
||||
public bool SelectAllOnGotFocus
|
||||
{
|
||||
get
|
||||
{
|
||||
return ( bool )GetValue( SelectAllOnGotFocusProperty );
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue( SelectAllOnGotFocusProperty, value );
|
||||
}
|
||||
}
|
||||
|
||||
#endregion //SelectAllOnGotFocus
|
||||
|
||||
#endregion //Properties
|
||||
|
||||
#region Methods
|
||||
|
||||
protected static decimal ParsePercent( string text, IFormatProvider cultureInfo )
|
||||
{
|
||||
NumberFormatInfo info = NumberFormatInfo.GetInstance( cultureInfo );
|
||||
|
||||
text = text.Replace( info.PercentSymbol, null );
|
||||
|
||||
decimal result = Decimal.Parse( text, NumberStyles.Any, info );
|
||||
result = result / 100;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion //Methods
|
||||
}
|
||||
|
||||
#pragma warning restore 0618
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
internal class SByteUpDown : CommonNumericUpDown<sbyte>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static SByteUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( SByteUpDown ), ( sbyte )1, sbyte.MinValue, sbyte.MaxValue );
|
||||
}
|
||||
|
||||
public SByteUpDown()
|
||||
: base( sbyte.TryParse, Decimal.ToSByte, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override sbyte IncrementValue( sbyte value, sbyte increment )
|
||||
{
|
||||
return ( sbyte )( value + increment );
|
||||
}
|
||||
|
||||
protected override sbyte DecrementValue( sbyte value, sbyte increment )
|
||||
{
|
||||
return ( sbyte )( value - increment );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class ShortUpDown : CommonNumericUpDown<short>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static ShortUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( ShortUpDown ), ( short )1, short.MinValue, short.MaxValue );
|
||||
}
|
||||
|
||||
public ShortUpDown()
|
||||
: base( Int16.TryParse, Decimal.ToInt16, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override short IncrementValue( short value, short increment )
|
||||
{
|
||||
return ( short )( value + increment );
|
||||
}
|
||||
|
||||
protected override short DecrementValue( short value, short increment )
|
||||
{
|
||||
return ( short )( value - increment );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
public class SingleUpDown : CommonNumericUpDown<float>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static SingleUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( SingleUpDown ), 1f, float.NegativeInfinity, float.PositiveInfinity );
|
||||
}
|
||||
|
||||
public SingleUpDown()
|
||||
: base( Single.TryParse, Decimal.ToSingle, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
#region AllowInputSpecialValues
|
||||
|
||||
public static readonly DependencyProperty AllowInputSpecialValuesProperty =
|
||||
DependencyProperty.Register( "AllowInputSpecialValues", typeof( AllowedSpecialValues ), typeof( SingleUpDown ), new UIPropertyMetadata( AllowedSpecialValues.None ) );
|
||||
|
||||
public AllowedSpecialValues AllowInputSpecialValues
|
||||
{
|
||||
get { return ( AllowedSpecialValues )GetValue( AllowInputSpecialValuesProperty ); }
|
||||
set { SetValue( AllowInputSpecialValuesProperty, value ); }
|
||||
}
|
||||
|
||||
#endregion //AllowInputSpecialValues
|
||||
|
||||
#endregion
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override float? OnCoerceIncrement( float? baseValue )
|
||||
{
|
||||
if( baseValue.HasValue && float.IsNaN( baseValue.Value ) )
|
||||
throw new ArgumentException( "NaN is invalid for Increment." );
|
||||
|
||||
return base.OnCoerceIncrement( baseValue );
|
||||
}
|
||||
|
||||
protected override float? OnCoerceMaximum( float? baseValue )
|
||||
{
|
||||
if( baseValue.HasValue && float.IsNaN( baseValue.Value ) )
|
||||
throw new ArgumentException( "NaN is invalid for Maximum." );
|
||||
|
||||
return base.OnCoerceMaximum( baseValue );
|
||||
}
|
||||
|
||||
protected override float? OnCoerceMinimum( float? baseValue )
|
||||
{
|
||||
if( baseValue.HasValue && float.IsNaN( baseValue.Value ) )
|
||||
throw new ArgumentException( "NaN is invalid for Minimum." );
|
||||
|
||||
return base.OnCoerceMinimum( baseValue );
|
||||
}
|
||||
|
||||
protected override float IncrementValue( float value, float increment )
|
||||
{
|
||||
return value + increment;
|
||||
}
|
||||
|
||||
protected override float DecrementValue( float value, float increment )
|
||||
{
|
||||
return value - increment;
|
||||
}
|
||||
|
||||
protected override void SetValidSpinDirection()
|
||||
{
|
||||
if( Value.HasValue && float.IsInfinity( Value.Value ) && ( Spinner != null ) )
|
||||
{
|
||||
Spinner.ValidSpinDirection = ValidSpinDirections.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
base.SetValidSpinDirection();
|
||||
}
|
||||
}
|
||||
|
||||
protected override float? ConvertTextToValue( string text )
|
||||
{
|
||||
float? result = base.ConvertTextToValue( text );
|
||||
|
||||
if( result != null )
|
||||
{
|
||||
if( float.IsNaN( result.Value ) )
|
||||
TestInputSpecialValue( this.AllowInputSpecialValues, AllowedSpecialValues.NaN );
|
||||
else if( float.IsPositiveInfinity( result.Value ) )
|
||||
TestInputSpecialValue( this.AllowInputSpecialValues, AllowedSpecialValues.PositiveInfinity );
|
||||
else if( float.IsNegativeInfinity( result.Value ) )
|
||||
TestInputSpecialValue( this.AllowInputSpecialValues, AllowedSpecialValues.NegativeInfinity );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
internal class UIntegerUpDown : CommonNumericUpDown<uint>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static UIntegerUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( UIntegerUpDown ), ( uint )1, uint.MinValue, uint.MaxValue );
|
||||
}
|
||||
|
||||
public UIntegerUpDown()
|
||||
: base( uint.TryParse, Decimal.ToUInt32, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override uint IncrementValue( uint value, uint increment )
|
||||
{
|
||||
return ( uint )( value + increment );
|
||||
}
|
||||
|
||||
protected override uint DecrementValue( uint value, uint increment )
|
||||
{
|
||||
return ( uint )( value - increment );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
internal class ULongUpDown : CommonNumericUpDown<ulong>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static ULongUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( ULongUpDown ), ( ulong )1, ulong.MinValue, ulong.MaxValue );
|
||||
}
|
||||
|
||||
public ULongUpDown()
|
||||
: base( ulong.TryParse, Decimal.ToUInt64, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override ulong IncrementValue( ulong value, ulong increment )
|
||||
{
|
||||
return ( ulong )( value + increment );
|
||||
}
|
||||
|
||||
protected override ulong DecrementValue( ulong value, ulong increment )
|
||||
{
|
||||
return ( ulong )( value - increment );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
***********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace Xceed.Wpf.Toolkit
|
||||
{
|
||||
internal class UShortUpDown : CommonNumericUpDown<ushort>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
static UShortUpDown()
|
||||
{
|
||||
UpdateMetadata( typeof( UShortUpDown ), ( ushort )1, ushort.MinValue, ushort.MaxValue );
|
||||
}
|
||||
|
||||
public UShortUpDown()
|
||||
: base( ushort.TryParse, Decimal.ToUInt16, ( v1, v2 ) => v1 < v2, ( v1, v2 ) => v1 > v2 )
|
||||
{
|
||||
}
|
||||
|
||||
#endregion //Constructors
|
||||
|
||||
#region Base Class Overrides
|
||||
|
||||
protected override ushort IncrementValue( ushort value, ushort increment )
|
||||
{
|
||||
return ( ushort )( value + increment );
|
||||
}
|
||||
|
||||
protected override ushort DecrementValue( ushort value, ushort increment )
|
||||
{
|
||||
return ( ushort )( value - increment );
|
||||
}
|
||||
|
||||
#endregion //Base Class Overrides
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<!--***********************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
**********************************************************************************-->
|
||||
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
|
||||
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes"
|
||||
xmlns:prim="clr-namespace:Xceed.Wpf.Toolkit.Primitives"
|
||||
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters">
|
||||
|
||||
<conv:InverseBoolConverter x:Key="InverseBoolConverter" />
|
||||
|
||||
<DataTemplate x:Key="DefaultWatermarkTemplate">
|
||||
<ContentControl Content="{Binding}"
|
||||
Foreground="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"
|
||||
Focusable="False"
|
||||
Margin="0,0,3,0" />
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="NumericUpDown"
|
||||
TargetType="{x:Type prim:InputBase}">
|
||||
<Setter Property="Background"
|
||||
Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
|
||||
<Setter Property="Foreground"
|
||||
Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
|
||||
<Setter Property="BorderBrush"
|
||||
Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBorderKey}}" />
|
||||
<Setter Property="BorderThickness"
|
||||
Value="1" />
|
||||
<Setter Property="HorizontalContentAlignment"
|
||||
Value="Right" />
|
||||
<Setter Property="IsTabStop"
|
||||
Value="False" />
|
||||
<Setter Property="VerticalContentAlignment"
|
||||
Value="Center" />
|
||||
<Setter Property="TextAlignment"
|
||||
Value="Right" />
|
||||
<Setter Property="WatermarkTemplate"
|
||||
Value="{StaticResource DefaultWatermarkTemplate}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Control">
|
||||
<local:ButtonSpinner x:Name="PART_Spinner"
|
||||
IsTabStop="False"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"
|
||||
AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ButtonSpinnerLocation="{Binding ButtonSpinnerLocation, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<local:WatermarkTextBox x:Name="PART_TextBox"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
ContextMenu="{TemplateBinding ContextMenu}"
|
||||
FontFamily="{TemplateBinding FontFamily}"
|
||||
FontSize="{TemplateBinding FontSize}"
|
||||
FontStretch="{TemplateBinding FontStretch}"
|
||||
FontStyle="{TemplateBinding FontStyle}"
|
||||
FontWeight="{TemplateBinding FontWeight}"
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
IsUndoEnabled="{Binding IsUndoEnabled, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
IsTabStop="True"
|
||||
MinWidth="20"
|
||||
AcceptsReturn="False"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SelectAllOnGotFocus="{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
AutoSelectBehavior="{Binding AutoSelectBehavior, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
AutoMoveFocus="{Binding AutoMoveFocus, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
TextWrapping="NoWrap"
|
||||
TabIndex="{TemplateBinding TabIndex}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</local:ButtonSpinner>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver"
|
||||
Value="True">
|
||||
<Setter Property="BorderBrush"
|
||||
Value="{DynamicResource {x:Static themes:ResourceKeys.ControlMouseOverBorderKey}}" />
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}"
|
||||
Value="False" />
|
||||
<Condition Binding="{Binding AllowTextInput, RelativeSource={RelativeSource Self}}"
|
||||
Value="False" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="IsReadOnly"
|
||||
Value="True"
|
||||
TargetName="PART_TextBox"/>
|
||||
</MultiDataTrigger>
|
||||
<DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}"
|
||||
Value="True">
|
||||
<Setter Property="IsReadOnly"
|
||||
Value="True"
|
||||
TargetName="PART_TextBox" />
|
||||
</DataTrigger>
|
||||
<Trigger Property="IsKeyboardFocusWithin"
|
||||
Value="True">
|
||||
<Setter Property="BorderBrush"
|
||||
Value="{DynamicResource {x:Static themes:ResourceKeys.ControlSelectedBorderKey}}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled"
|
||||
Value="False">
|
||||
<Setter Property="Foreground"
|
||||
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsFocused"
|
||||
Value="True">
|
||||
<Setter TargetName="PART_TextBox"
|
||||
Property="FocusManager.FocusedElement"
|
||||
Value="{Binding ElementName=PART_TextBox}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- DecimalUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:DecimalUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- DoubleUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:DoubleUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- IntegerUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:IntegerUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- ShortUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:ShortUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- LongUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:LongUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- ByteUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:ByteUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- SingleUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:SingleUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- Style for all internal derived types of NumericUpDown will be done in code-behind -->
|
||||
<!-- for external themes to redefine the default style. The reason is that the -->
|
||||
<!-- toolkit.dll uses the InternalsVisibleTo attribute which makes internal data only -->
|
||||
<!-- available in code-behind(not xaml). -->
|
||||
<!-- (ex. Office2007 theme) -->
|
||||
<!-- =============================================================================== -->
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- SByteUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:SByteUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- UIntegerUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:UIntegerUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- ULongUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:ULongUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- UShortUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:UShortUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
172
Src/Xceed.Wpf.Toolkit/NumericUpDown/Themes/Generic.xaml
Normal file
172
Src/Xceed.Wpf.Toolkit/NumericUpDown/Themes/Generic.xaml
Normal file
@@ -0,0 +1,172 @@
|
||||
<!--***********************************************************************************
|
||||
|
||||
Extended WPF Toolkit
|
||||
|
||||
Copyright (C) 2007-2013 Xceed Software Inc.
|
||||
|
||||
This program is provided to you under the terms of the Microsoft Public
|
||||
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
|
||||
|
||||
For more features, controls, and fast professional support,
|
||||
pick up the Plus Edition at http://xceed.com/wpf_toolkit
|
||||
|
||||
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
|
||||
|
||||
**********************************************************************************-->
|
||||
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Xceed.Wpf.Toolkit"
|
||||
xmlns:themes="clr-namespace:Xceed.Wpf.Toolkit.Themes"
|
||||
xmlns:prim="clr-namespace:Xceed.Wpf.Toolkit.Primitives"
|
||||
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Core.Converters">
|
||||
|
||||
<conv:InverseBoolConverter x:Key="InverseBoolConverter" />
|
||||
|
||||
<DataTemplate x:Key="DefaultWatermarkTemplate">
|
||||
<ContentControl Content="{Binding}" Foreground="Gray" Focusable="False" Margin="0,0,3,0" />
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="NumericUpDown" TargetType="{x:Type prim:InputBase}">
|
||||
<Setter Property="Background" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBackgroundKey}}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static themes:ResourceKeys.ControlNormalBorderKey}}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Right" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
<Setter Property="TextAlignment" Value="Right" />
|
||||
<Setter Property="WatermarkTemplate" Value="{StaticResource DefaultWatermarkTemplate}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Control">
|
||||
<local:ButtonSpinner x:Name="PART_Spinner"
|
||||
IsTabStop="False"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"
|
||||
AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ButtonSpinnerLocation="{Binding ButtonSpinnerLocation, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<local:WatermarkTextBox x:Name="PART_TextBox"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
ContextMenu="{TemplateBinding ContextMenu}"
|
||||
FontFamily="{TemplateBinding FontFamily}"
|
||||
FontSize="{TemplateBinding FontSize}"
|
||||
FontStretch="{TemplateBinding FontStretch}"
|
||||
FontStyle="{TemplateBinding FontStyle}"
|
||||
FontWeight="{TemplateBinding FontWeight}"
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
IsUndoEnabled="{Binding IsUndoEnabled, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
IsTabStop="True"
|
||||
MinWidth="20"
|
||||
AcceptsReturn="False"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SelectAllOnGotFocus="{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
AutoSelectBehavior="{Binding AutoSelectBehavior, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
AutoMoveFocus="{Binding AutoMoveFocus, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
TextWrapping="NoWrap"
|
||||
TabIndex="{TemplateBinding TabIndex}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}" />
|
||||
</local:ButtonSpinner>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}"
|
||||
Value="False" />
|
||||
<Condition Binding="{Binding AllowTextInput, RelativeSource={RelativeSource Self}}"
|
||||
Value="False" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter Property="IsReadOnly"
|
||||
Value="True"
|
||||
TargetName="PART_TextBox" />
|
||||
</MultiDataTrigger>
|
||||
<DataTrigger Binding="{Binding IsReadOnly, RelativeSource={RelativeSource Self}}"
|
||||
Value="True">
|
||||
<Setter Property="IsReadOnly"
|
||||
Value="True"
|
||||
TargetName="PART_TextBox" />
|
||||
</DataTrigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsFocused" Value="True">
|
||||
<Setter TargetName="PART_TextBox" Property="FocusManager.FocusedElement" Value="{Binding ElementName=PART_TextBox}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- DecimalUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:DecimalUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- DoubleUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:DoubleUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- IntegerUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:IntegerUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- ShortUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:ShortUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- LongUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:LongUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- ByteUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:ByteUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- SingleUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:SingleUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- Style for all internal derived types of NumericUpDown will be done in code-behind -->
|
||||
<!-- for external themes to redefine the default style. The reason is that the -->
|
||||
<!-- toolkit.dll uses the InternalsVisibleTo attribute which makes internal data only -->
|
||||
<!-- available in code-behind(not xaml). -->
|
||||
<!-- (ex. Office2007 theme) -->
|
||||
<!-- =============================================================================== -->
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- SByteUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:SByteUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- UIntegerUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:UIntegerUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- ULongUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:ULongUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
<!-- =============================================================================== -->
|
||||
<!-- UShortUpDown -->
|
||||
<!-- =============================================================================== -->
|
||||
<Style TargetType="{x:Type local:UShortUpDown}" BasedOn="{StaticResource NumericUpDown}" />
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user