Value change restriction in .NET MAUI NumericUpDown
8 Jan 20253 minutes to read
This section describes how to restrict the change in the value of the NumericUpDown control using AllowNull, Minimum, and Maximum properties.
Restrict null value
By default, an empty or null value is set in the NumericUpDown control when the input is cleared, as the default value of the AllowNull property is true. When the AllowNull property value is false, the NumericUpDown control returns the value to 0 in the editor after clearing the input.
NOTE
When the value of the
Minimumproperty is 15, and theAllowNullproperty is true, the null value is returned in theNumericUpDowncontrol after clearing the input.
NOTE
When the value of the Minimum property is 15, and the
AllowNullproperty is false, theminimumvalue is returned inNumericUpDowncontrol after clearing the input.
<editors:SfNumericUpDown HorizontalOptions="Center"
VerticalOptions="Center"
Value="10"
AllowNull="False" />SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.HorizontalOptions = LayoutOptions.Center;
sfNumericUpDown.VerticalOptions = LayoutOptions.Center;
sfNumericUpDown.Value = 10;
sfNumericUpDown.AllowNull = false;
Restrict value within range
You can restrict the users to enter input within a minimum and maximum range in the NumericUpDown control using the Minimum and Maximum properties. The default value of the Minimum property is the double.MinValue and Maximum property is double.MaxValue.
<editors:SfNumericUpDown HorizontalOptions="Center"
VerticalOptions="Center"
Value="50"
Minimum="10"
Maximum="30" />SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.HorizontalOptions = LayoutOptions.Center;
sfNumericUpDown.VerticalOptions = LayoutOptions.Center;
sfNumericUpDown.Minimum = 10;
sfNumericUpDown.Maximum = 30;
sfNumericUpDown.Value = 50;
Restrict text editing
You can prevent users from editing the numerical value in the editor using the IsEditable property. However, you can still change the value using the up-down buttons, mouse scroll, keyboard arrows, and page keys. By default, the value of the IsEditable property is true.
<editors:SfNumericUpDown x:Name="sfNumericUpDown"
HorizontalOptions="Center"
VerticalOptions="Center"
IsEditable="True" />SfNumericUpDown sfNumericUpDown = new SfNumericUpDown();
sfNumericUpDown.HorizontalOptions = LayoutOptions.Center;
sfNumericUpDown.VerticalOptions = LayoutOptions.Center;
sfNumericUpDown.IsEditable = true;