Syncfusion AI Assistant

How can I help you?

Basic Features in .NET MAUI Numeric UpDown (SfNumericUpDown)

Setting Placeholder Text

You can prompt the user with any information using the Placeholder property. Placeholder text will be displayed only when the value of the AllowNull property is true and the value of the NumericUpDown control is null. The default value of the Placeholder property is string.Empty (No string will be displayed).

<editors:SfNumericUpDown HorizontalOptions="Center" 
                     VerticalOptions="Center" 
                     Placeholder="Enter input here..." />
SfNumericUpDown numericUpDown= new SfNumericUpDown();
numericUpDown.Placeholder = "Enter input here...";
numericUpDown.HorizontalOptions = LayoutOptions.Center;
numericUpDown.VerticalOptions = LayoutOptions.Center;

.NET MAUI NumericUpDown Placeholder Text

Placeholder Color

The PlaceholderColor property is used to customize the color of the placeholder text in the NumericUpDown. By default, the placeholder uses the control’s default text color.

<editors:SfNumericUpDown AllowNull="True"
                         Placeholder="Enter value here..."
                         PlaceholderColor="Red" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.AllowNull = true;
sfNumericUpDown.Placeholder = "Enter value here...";
sfNumericUpDown.PlaceholderColor = Colors.Red;

Clear button visibility

The ShowClearButton property is used to show or hide the clear button in the NumericUpDown. By default, visibility of the clear button is enabled.

NOTE

The clear button appears only when the text box is focused and the IsEditable property value is set to true.

<editors:SfNumericUpDown ShowClearButton="True" 
                         IsEditable="True" 
                         Value="10"/>
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.Value=10;
sfNumericUpDown.ShowClearButton = true;
sfNumericUpDown.IsEditable = true;

If IsEditable is true

.NET MAUI NumericUpDown with Clear Button

If IsEditable is false

.NET MAUI NumericUpDown without Clear Button

Clear Button Color

The ClearButtonColor property is used to customize the color of the clear button in the NumericUpDown. By default, the clear button uses the control’s default tint.

<editors:SfNumericUpDown ShowClearButton="True"
                         IsEditable="True"
                         Value="10"
                         ClearButtonColor="Red" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.Value = 10;
sfNumericUpDown.ShowClearButton = true;
sfNumericUpDown.IsEditable = true;
sfNumericUpDown.ClearButtonColor = Colors.Red;

Value Change Mode

The ValueChangeMode property determine when the values are updated.

The supported value change modes are as follows:
* OnLostFocus - The value will be updated when the editor loses its focus or the focus moved to the next control. By default, the ValueChangeMode is OnLostFocus.
* OnKeyFocus - The value will be updated with each key press.

<VerticalStackLayout Spacing="10" VerticalOptions="Center">
    <editors:SfNumericUpDown x:Name="NumericUpDown"
                            WidthRequest="200"
                            HeightRequest="40" 
                            VerticalOptions="Center"
                            ValueChangeMode="OnKeyFocus"
                            Value="50">
    </editors:SfNumericUpDown>
    <HorizontalStackLayout Spacing="2" HeightRequest="40" WidthRequest="200">
        <Label Text="Dollar:"  />
        <Label x:Name="valueDisplay" 
               TextColor="Green" 
               Text="{Binding Path=Value, Source={x:Reference NumericUpDown}, StringFormat='${0:F2}'}" 
               HeightRequest="40" />
    </HorizontalStackLayout>
</VerticalStackLayout>
public partial class MainPage : ContentPage
{
    public Label valueDisplay;
    public MainPage()
    {
        InitializeComponent();
        var verticalStackLayout = new StackLayout
        {
            Spacing = 10,
            VerticalOptions = LayoutOptions.Center
        };
        var NumericUpDown = new SfNumericUpDown
        {
            WidthRequest = 200,
            HeightRequest = 40,
            VerticalOptions = LayoutOptions.Center,
            ValueChangeMode = ValueChangeMode.OnKeyFocus,
            Value = 50
        };
        var horizontalStackLayout = new StackLayout
        {
            Spacing = 2,
            HeightRequest = 40,
            WidthRequest = 200
        };
        var labelDollar = new Label
        {
            Text = "Dollar:"
        };
        valueDisplay = new Label
        {
            Text="$50",
            TextColor = Colors.Green
        };
        NumericUpDown.ValueChanged += NumericUpDown_ValueChanged;
        horizontalStackLayout.Children.Add(labelDollar);
        horizontalStackLayout.Children.Add(valueDisplay);
        verticalStackLayout.Children.Add(NumericUpDown);
        verticalStackLayout.Children.Add(horizontalStackLayout);
        Content = verticalStackLayout;
    }

    private void NumericUpDown_ValueChanged(object sender, NumericUpDownValueChangedEventArgs e)
    {
        valueDisplay.Text="$"+e.NewValue.ToString();
    }
}

.NET MAUI NumericUpDown with ValueChange Mode

Stroke

The NumericUpDown border color can be changed by using the Stroke property. The default Stroke color is Black.

<editors:SfNumericUpDown HorizontalOptions="Center"
                        VerticalOptions="Center"
                        Stroke="Red" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.HorizontalOptions = LayoutOptions.Center;
sfNumericUpDown.VerticalOptions = LayoutOptions.Center;
sfNumericUpDown.Stroke = Colors.Red;

Border visibility

The ShowBorder property of SfNumericUpDown is used to modify the visibility of the border and its default value is true. The following code example demonstrates how to change the border visibility,

<editors:SfNumericUpDown WidthRequest="200"
                        HeightRequest="40"
                        ShowBorder="False"/>
SfNumericUpDown sfNumericUpDown= new SfNumericUpDown();
sfNumericUpDown.WidthRequest = 200;
sfNumericUpDown.HeightRequest = 40;
sfNumericUpDown.ShowBorder = false;

The following image illustrates the result of the above code:

.NET MAUI NumericUpDown ShowBorder

TextAlignment

The SfNumericUpDown provides support to customize the text alignment by using the HorizontalTextAlignment and VerticalTextAlignment properties.

NOTE

Dynamic changes to the HorizontalTextAlignment property may not be functioning as expected on Android platform.

<editors:SfNumericUpDown WidthRequest="200"
                        HeightRequest="50"
                        HorizontalTextAlignment="Center" 
                        VerticalTextAlignment="Start"/>
SfNumericUpDown sfNumericUpDown= new SfNumericUpDown();
sfNumericUpDown.WidthRequest = 200;
sfNumericUpDown.HeightRequest = 50;
sfNumericUpDown.HorizontalTextAlignment = TextAlignment.Center;
sfNumericUpDown.VerticalTextAlignment = TextAlignment.Start;

The following image illustrates the result of the above code:

HorizontalTextAlignment

Text Color

The TextColor property is used to customize the color of the text in the NumericUpDown. By default, the control uses its standard text color.

<editors:SfNumericUpDown Value="100"
                         TextColor="Blue" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.Value = 100;
sfNumericUpDown.TextColor = Colors.Blue;

Font Customization

The NumericUpDown control allows you to customize the font of the displayed text using the FontFamily, FontSize, and FontAttributes properties.

<editors:SfNumericUpDown Value="100"
                         FontFamily="OpenSansRegular"
                         FontSize="20"
                         FontAttributes="Bold" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.Value = 100;
sfNumericUpDown.FontFamily = "OpenSansRegular";
sfNumericUpDown.FontSize = 20;
sfNumericUpDown.FontAttributes = FontAttributes.Bold;

Cursor Position

The CursorPosition property allows you to get or set the position of the cursor in the NumericUpDown control. The default value of the CursorPosition property is 0.

<editors:SfNumericUpDown Value="12345"
                         CursorPosition="3" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.Value = 12345;
sfNumericUpDown.CursorPosition = 3;

Selection Length

The SelectionLength property allows you to get or set the length of the selected text in the NumericUpDown control. The default value of the SelectionLength property is 0.

<editors:SfNumericUpDown Value="12345"
                         CursorPosition="0"
                         SelectionLength="3" />
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.Value = 12345;
sfNumericUpDown.CursorPosition = 0;
sfNumericUpDown.SelectionLength = 3;

ReturnType

The ReturnType property specifies the return button (e.g., Next, Done, Go) of the keyboard. It helps manage the flow between multiple input fields by defining what happens when the action button is pressed.

You can define the return key type of SfNumericUpDown by using the ReturnType property.

NOTE

Default value of ReturnType is Default.

<editors:SfNumericUpDown x:Name="NumericUpDown" 
                        WidthRequest="200"
                        ReturnType="Next"/>
SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.ReturnType = ReturnType.Next;

.NET MAUI NumericUpDown ReturnType

Clear button customization

The ClearButtonPath property allows users to set the path for customizing the appearance of the SfNumericUpDown clear button.

<editors:SfNumericUpDown x:Name="NumericUpDown"
                        ShowClearButton="True" 
                        IsEditable="True" 
                        Value="10">
            <editors:SfNumericUpDown.ClearButtonPath>
                <Path Data="M1.70711 0.292893C1.31658 -0.097631 0.683417 -0.097631 0.292893 0.292893C-0.097631 0.683417 -0.097631 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.097631 12.6834 -0.097631 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.097631 12.6834 -0.097631 12.2929 0.292893L7 5.58579L1.70711 0.292893Z" 
                Fill="Red" 
                Stroke="Red"/>
            </editors:SfNumericUpDown.ClearButtonPath>
</editors:SfNumericUpDown>
private string _customPath = "M1.70711 0.292893C1.31658 -0.097631 0.683417 -0.097631 0.292893 0.292893C-0.097631 0.683417 -0.097631 1.31658 0.292893 1.70711L5.58579 7L0.292893 12.2929C-0.097631 12.6834 -0.097631 13.3166 0.292893 13.7071C0.683417 14.0976 1.31658 14.0976 1.70711 13.7071L7 8.41421L12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L8.41421 7L13.7071 1.70711C14.0976 1.31658 14.0976 0.683417 13.7071 0.292893C13.3166 -0.097631 12.6834 -0.097631 12.2929 0.292893L7 5.58579L1.70711 0.292893Z";

var converter = new PathGeometryConverter();
var path = new Path() 
{ 
    Data = (PathGeometry)converter.ConvertFromInvariantString(_customPath),
    Fill = Colors.Red,
    Stroke = Colors.Red
};

SfNumericUpDown numericUpDown = new SfNumericUpDown();
numericUpDown.Value=10;
numericUpDown.ShowClearButton = true;
numericUpDown.IsEditable = true; 
numericUpDown.ClearButtonPath = path;

The following image illustrates the result of the above code:

.NET MAUI NumericUpDown ClearButtonPath

Return Command and Return Command Parameter

  • ReturnCommand, of type ICommand, defines the command to be executed when the return key is pressed.
  • ReturnCommandParameter, of type object, specifies the parameter for the ReturnCommand.
<ContentPage.BindingContext>
    <local:CommandDemoViewModel/>
</ContentPage.BindingContext>

<editors:SfNumericUpDown x:Name="NumericUpDown"
            ReturnCommand="{Binding AlertCommand}"
            ReturnCommandParameter="Return key is pressed">
</editors:SfNumericUpDown>
var viewModel = new CommandDemoViewModel();
SfNumericUpDown NumericUpDown = new SfNumericUpDown();
NumericUpDown.ReturnCommand = viewModel.AlertCommand;
NumericUpDown.ReturnCommandParameter = "Return key is pressed";
//ViewModel.cs

public class CommandDemoViewModel
{
    public ICommand AlertCommand => new Command<string>(OnAlertCommandExecuted);

    private async void OnAlertCommandExecuted(string parameter)
    {
        await Application.Current.MainPage.DisplayAlert("Alert", parameter, "OK");
    }
}