All the controls missing in WPF. Over 1 million downloads.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

using System;
using System.Windows;
namespace Microsoft.Windows.Controls
{
public class IntegerUpDown : NumericUpDown<int?>
{
#region Constructors
static IntegerUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(typeof(IntegerUpDown)));
DefaultValueProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(0));
IncrementProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(1));
MaximumProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(int.MaxValue));
MinimumProperty.OverrideMetadata(typeof(IntegerUpDown), new FrameworkPropertyMetadata(int.MinValue));
}
#endregion //Constructors
#region Base Class Overrides
protected override void CoerceValue(int? value)
{
if (value < Minimum)
Value = Minimum;
else if (value > Maximum)
Value = Maximum;
}
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 int? ConvertTextToValue(string text)
{
int? result = null;
if (String.IsNullOrEmpty(text))
return result;
try
{
//don't know why someone would format an integer as %, but just in case they do.
result = FormatString.Contains("P") ? Decimal.ToInt32(ParsePercent(text, CultureInfo)) : ParseInt(text, CultureInfo);
}
catch
{
Text = ConvertValueToText();
return Value;
}
return result;
}
protected override string ConvertValueToText()
{
if (Value == null)
return string.Empty;
return Value.Value.ToString(FormatString, CultureInfo);
}
#endregion //Base Class Overrides
}
}