Value Change Restriction in .NET MAUI Numeric Entry

21 Jul 20265 minutes to read

This section describes how to restrict value changes in the SfNumericEntry control using the AllowNull, Minimum, and Maximum properties, and how to prevent text editing with the IsEditable property.

Prerequisites

Before using the SfNumericEntry, ensure the following NuGet package is installed in your .NET MAUI project:

  • Syncfusion.Maui.Inputs

For a step-by-step setup, refer to the Getting Started documentation.

Restrict null value

By default, an empty or null value is set in the Numeric Entry control when the input is cleared, because the default value of the AllowNull property is true. The Value property is of type double?; when AllowNull is true, clearing the input sets Value to null. When AllowNull is false, the control restores the value to 0 (or to Minimum, if Minimum is greater than 0) after the input is cleared.

NOTE

The behavior after clearing the input depends on the combination of AllowNull and Minimum:

  • When the value of the Minimum property is 15, and the AllowNull property is true, the null value is returned in the Numeric Entry control after clearing the input.
  • When the value of the Minimum property is 15, and the AllowNull property is false, the Minimum value is returned in Numeric Entry control after clearing the input.
<editors:SfNumericEntry WidthRequest="200"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"
                        Value="10"
                        AllowNull="False" />
SfNumericEntry sfNumericEntry = new SfNumericEntry
{
    WidthRequest = 200,
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center,
    Value = 10,
    AllowNull = false,
};

.NET MAUI NumericEntry with AllowNull set to false

Restrict value within range

Restrict user input to a minimum and maximum range by setting the Minimum and Maximum properties. The default value of Minimum is double.MinValue and the default value of Maximum is double.MaxValue. When the user enters a value outside the range, the control rejects the invalid input and keeps the previous Value.

<editors:SfNumericEntry WidthRequest="200"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"
                        Value="20"
                        Minimum="10"
                        Maximum="30" />
SfNumericEntry sfNumericEntry = new SfNumericEntry
{
    WidthRequest = 200,
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center,
    Minimum = 10,
    Maximum = 30,
    Value = 20,
};

.NET MAUI NumericEntry value restricted to a minimum and maximum

Prevent text editing

Prevent the user from typing in the editor by setting the IsEditable property to false. Even when text editing is disabled, the value can still be changed using the up-down buttons, the mouse scroll wheel, the keyboard arrow keys, and the Page Up/Page Down keys. The default value of IsEditable is true.

<editors:SfNumericEntry x:Name="sfNumericEntry"
                        WidthRequest="200"
                        HorizontalOptions="Center"
                        VerticalOptions="Center"
                        IsEditable="False" />
SfNumericEntry sfNumericEntry = new SfNumericEntry
{
    WidthRequest = 200,
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center,
    IsEditable = false,
};

See Also