Table of Contents

Class NumericUpDown

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Control that represents a TextBox with button spinners that allow incrementing and decrementing numeric values.

[TemplatePart("PART_Spinner", typeof(Spinner))]
[TemplatePart("PART_TextBox", typeof(TextBox), IsRequired = true)]
public class NumericUpDown : TemplatedControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue
Inheritance
NumericUpDown
Implements
Inherited Members
Extension Methods

Constructors

NumericUpDown()

Initializes new instance of NumericUpDown class.

public NumericUpDown()

Fields

AllowSpinProperty

Defines the AllowSpin property.

public static readonly StyledProperty<bool> AllowSpinProperty

Field Value

StyledProperty<bool>

ButtonSpinnerLocationProperty

Defines the ButtonSpinnerLocation property.

public static readonly StyledProperty<Location> ButtonSpinnerLocationProperty

Field Value

StyledProperty<Location>

ClipValueToMinMaxProperty

Defines the ClipValueToMinMax property.

public static readonly StyledProperty<bool> ClipValueToMinMaxProperty

Field Value

StyledProperty<bool>

FormatStringProperty

Defines the FormatString property.

public static readonly StyledProperty<string> FormatStringProperty

Field Value

StyledProperty<string>

HorizontalContentAlignmentProperty

Defines the HorizontalContentAlignment property.

public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty

Field Value

StyledProperty<HorizontalAlignment>

IncrementProperty

Defines the Increment property.

public static readonly StyledProperty<decimal> IncrementProperty

Field Value

StyledProperty<decimal>

InnerLeftContentProperty

Defines the InnerLeftContent property

public static readonly StyledProperty<object?> InnerLeftContentProperty

Field Value

StyledProperty<object>

InnerRightContentProperty

Defines the InnerRightContent property

public static readonly StyledProperty<object?> InnerRightContentProperty

Field Value

StyledProperty<object>

IsReadOnlyProperty

Defines the IsReadOnly property.

public static readonly StyledProperty<bool> IsReadOnlyProperty

Field Value

StyledProperty<bool>

MaximumProperty

Defines the Maximum property.

public static readonly StyledProperty<decimal> MaximumProperty

Field Value

StyledProperty<decimal>

MinimumProperty

Defines the Minimum property.

public static readonly StyledProperty<decimal> MinimumProperty

Field Value

StyledProperty<decimal>

NumberFormatProperty

Defines the NumberFormat property.

public static readonly StyledProperty<NumberFormatInfo?> NumberFormatProperty

Field Value

StyledProperty<NumberFormatInfo>

ParsingNumberStyleProperty

Defines the ParsingNumberStyle property.

public static readonly StyledProperty<NumberStyles> ParsingNumberStyleProperty

Field Value

StyledProperty<NumberStyles>

ShowButtonSpinnerProperty

Defines the ShowButtonSpinner property.

public static readonly StyledProperty<bool> ShowButtonSpinnerProperty

Field Value

StyledProperty<bool>

TextAlignmentProperty

Defines the TextAlignment property

public static readonly StyledProperty<TextAlignment> TextAlignmentProperty

Field Value

StyledProperty<TextAlignment>

TextConverterProperty

Defines the TextConverter property.

public static readonly StyledProperty<IValueConverter?> TextConverterProperty

Field Value

StyledProperty<IValueConverter>

TextProperty

Defines the Text property.

public static readonly StyledProperty<string?> TextProperty

Field Value

StyledProperty<string>

ValueChangedEvent

Defines the ValueChanged event.

public static readonly RoutedEvent<NumericUpDownValueChangedEventArgs> ValueChangedEvent

Field Value

RoutedEvent<NumericUpDownValueChangedEventArgs>

ValueProperty

Defines the Value property.

public static readonly StyledProperty<decimal?> ValueProperty

Field Value

StyledProperty<decimal?>

VerticalContentAlignmentProperty

Defines the VerticalContentAlignment property.

public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty

Field Value

StyledProperty<VerticalAlignment>

WatermarkProperty

Defines the Watermark property.

public static readonly StyledProperty<string?> WatermarkProperty

Field Value

StyledProperty<string>

Properties

AllowSpin

Gets or sets the ability to perform increment/decrement operations via the keyboard, button spinners, or mouse wheel.

public bool AllowSpin { get; set; }

Property Value

bool

ButtonSpinnerLocation

Gets or sets current location of the ButtonSpinner.

public Location ButtonSpinnerLocation { get; set; }

Property Value

Location

ClipValueToMinMax

Gets or sets if the value should be clipped when minimum/maximum is reached.

public bool ClipValueToMinMax { get; set; }

Property Value

bool

FormatString

Gets or sets the display format of the Value.

public string FormatString { get; set; }

Property Value

string

HorizontalContentAlignment

Gets or sets the horizontal alignment of the content within the control.

public HorizontalAlignment HorizontalContentAlignment { get; set; }

Property Value

HorizontalAlignment

Increment

Gets or sets the amount in which to increment the Value.

public decimal Increment { get; set; }

Property Value

decimal

InnerLeftContent

Gets or sets custom content that is positioned on the left side of the text layout box

public object? InnerLeftContent { get; set; }

Property Value

object

InnerRightContent

Gets or sets custom content that is positioned on the right side of the text layout box

public object? InnerRightContent { get; set; }

Property Value

object

IsReadOnly

Gets or sets if the control is read only.

public bool IsReadOnly { get; set; }

Property Value

bool

Maximum

Gets or sets the maximum allowed value.

public decimal Maximum { get; set; }

Property Value

decimal

Minimum

Gets or sets the minimum allowed value.

public decimal Minimum { get; set; }

Property Value

decimal

NumberFormat

Gets or sets the current NumberFormatInfo

public NumberFormatInfo? NumberFormat { get; set; }

Property Value

NumberFormatInfo

ParsingNumberStyle

Gets or sets the parsing style (AllowLeadingWhite, Float, AllowHexSpecifier, ...). By default, Any. Note that Hex style does not work with decimal. For hexadecimal display, use TextConverter.

public NumberStyles ParsingNumberStyle { get; set; }

Property Value

NumberStyles

ShowButtonSpinner

Gets or sets a value indicating whether the spin buttons should be shown.

public bool ShowButtonSpinner { get; set; }

Property Value

bool

Text

Gets or sets the formatted string representation of the value.

public string? Text { get; set; }

Property Value

string

TextAlignment

Gets or sets the TextAlignment of the NumericUpDown

public TextAlignment TextAlignment { get; set; }

Property Value

TextAlignment

TextConverter

Gets or sets the custom bidirectional Text-Value converter. Non-null converter overrides ParsingNumberStyle, providing finer control over string representation of the underlying value.

public IValueConverter? TextConverter { get; set; }

Property Value

IValueConverter

Value

Gets or sets the value.

public decimal? Value { get; set; }

Property Value

decimal?

VerticalContentAlignment

Gets or sets the vertical alignment of the content within the control.

public VerticalAlignment VerticalContentAlignment { get; set; }

Property Value

VerticalAlignment

Watermark

Gets or sets the object to use as a watermark if the Value is null.

public string? Watermark { get; set; }

Property Value

string

Methods

OnApplyTemplate(TemplateAppliedEventArgs)

Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

Parameters

e TemplateAppliedEventArgs

The event args.

OnCoerceIncrement(decimal)

Called when the Increment property has to be coerced.

protected virtual decimal OnCoerceIncrement(decimal baseValue)

Parameters

baseValue decimal

The value.

Returns

decimal

OnCoerceMaximum(decimal)

Called when the Maximum property has to be coerced.

protected virtual decimal OnCoerceMaximum(decimal baseValue)

Parameters

baseValue decimal

The value.

Returns

decimal

OnCoerceMinimum(decimal)

Called when the Minimum property has to be coerced.

protected virtual decimal OnCoerceMinimum(decimal baseValue)

Parameters

baseValue decimal

The value.

Returns

decimal

OnCoerceValue(decimal?)

Called when the Value property has to be coerced.

protected virtual decimal? OnCoerceValue(decimal? baseValue)

Parameters

baseValue decimal?

The value.

Returns

decimal?

OnFormatStringChanged(string?, string?)

Called when the FormatString property value changed.

protected virtual void OnFormatStringChanged(string? oldValue, string? newValue)

Parameters

oldValue string

The old value.

newValue string

The new value.

OnGotFocus(GotFocusEventArgs)

Called before the GotFocus event occurs.

protected override void OnGotFocus(GotFocusEventArgs e)

Parameters

e GotFocusEventArgs

The event args.

OnIncrementChanged(decimal, decimal)

Called when the Increment property value changed.

protected virtual void OnIncrementChanged(decimal oldValue, decimal newValue)

Parameters

oldValue decimal

The old value.

newValue decimal

The new value.

OnIsReadOnlyChanged(bool, bool)

Called when the IsReadOnly property value changed.

protected virtual void OnIsReadOnlyChanged(bool oldValue, bool newValue)

Parameters

oldValue bool

The old value.

newValue bool

The new value.

OnKeyDown(KeyEventArgs)

Called before the KeyDown event occurs.

protected override void OnKeyDown(KeyEventArgs e)

Parameters

e KeyEventArgs

The event args.

OnLostFocus(RoutedEventArgs)

Called before the LostFocus event occurs.

protected override void OnLostFocus(RoutedEventArgs e)

Parameters

e RoutedEventArgs

The event args.

OnMaximumChanged(decimal, decimal)

Called when the Maximum property value changed.

protected virtual void OnMaximumChanged(decimal oldValue, decimal newValue)

Parameters

oldValue decimal

The old value.

newValue decimal

The new value.

OnMinimumChanged(decimal, decimal)

Called when the Minimum property value changed.

protected virtual void OnMinimumChanged(decimal oldValue, decimal newValue)

Parameters

oldValue decimal

The old value.

newValue decimal

The new value.

OnNumberFormatChanged(NumberFormatInfo?, NumberFormatInfo?)

Called when the NumberFormat property value changed.

protected virtual void OnNumberFormatChanged(NumberFormatInfo? oldValue, NumberFormatInfo? newValue)

Parameters

oldValue NumberFormatInfo

The old value.

newValue NumberFormatInfo

The new value.

OnSpin(SpinEventArgs)

Raises the OnSpin event when spinning is initiated by the end-user.

protected virtual void OnSpin(SpinEventArgs e)

Parameters

e SpinEventArgs

The event args.

OnTextChanged(string?, string?)

Called when the Text property value changed.

protected virtual void OnTextChanged(string? oldValue, string? newValue)

Parameters

oldValue string

The old value.

newValue string

The new value.

OnTextConverterChanged(IValueConverter?, IValueConverter?)

Called when the Text property value changed.

protected virtual void OnTextConverterChanged(IValueConverter? oldValue, IValueConverter? newValue)

Parameters

oldValue IValueConverter

The old value.

newValue IValueConverter

The new value.

OnValueChanged(decimal?, decimal?)

Called when the Value property value changed.

protected virtual void OnValueChanged(decimal? oldValue, decimal? newValue)

Parameters

oldValue decimal?

The old value.

newValue decimal?

The new value.

RaiseValueChangedEvent(decimal?, decimal?)

Raises the ValueChanged event.

protected virtual void RaiseValueChangedEvent(decimal? oldValue, decimal? newValue)

Parameters

oldValue decimal?

The old value.

newValue decimal?

The new value.

UpdateDataValidation(AvaloniaProperty, BindingValueType, Exception?)

Called to update the validation state for properties for which data validation is enabled.

protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)

Parameters

property AvaloniaProperty

The property.

state BindingValueType

The current data binding state.

error Exception

The current data binding error, if any.

Events

Spinned

public event EventHandler<SpinEventArgs>? Spinned

Event Type

EventHandler<SpinEventArgs>

ValueChanged

Raised when the Value changes.

public event EventHandler<NumericUpDownValueChangedEventArgs>? ValueChanged

Event Type

EventHandler<NumericUpDownValueChangedEventArgs>