How can I help you?
Value change restriction in WinUI NumberBox
16 Mar 20263 minutes to read
This section describes how to restrict the change in value of the NumberBox control using AllowNull, Minimum, and Maximum properties.
Restrict null value
By default, an empty or null value is set in the NumberBox control when the input is cleared, as the default value of the AllowNull property is true. When the AllowNull property value is false, the NumberBox control return the value to 0 in the editor after clearing the input.
NOTE
When the value of the
Minimumproperty is 15 and theAllowNullproperty is true, null value is returned inNumberBoxcontrol after clearing the input.
NOTE
When the value of the
Minimumproperty is 15 and theAllowNullproperty is false, the minimum value is returned inNumberBoxcontrol after clearing the input.
<editors:SfNumberBox HorizontalAlignment="Center"
VerticalAlignment="Center"
Value="10"
AllowNull="False" />SfNumberBox sfNumberBox = new SfNumberBox();
sfNumberBox.HorizontalAlignment = HorizontalAlignment.Center;
sfNumberBox.VerticalAlignment = VerticalAlignment.Center;
sfNumberBox.Value = 10;
sfNumberBox.AllowNull = false;
Restrict value within range
You can restrict the users to enter input within a minimum and maximum range in NumberBox control using the Minimum andMaximum properties. The default value of the Minimum property is null and Maximum property is null.
<editors:SfNumberBox HorizontalAlignment="Center"
VerticalAlignment="Center"
Value="50"
Minimum="10"
Maximum="30" />SfNumberBox sfNumberBox = new SfNumberBox();
sfNumberBox.HorizontalAlignment = HorizontalAlignment.Center;
sfNumberBox.VerticalAlignment = VerticalAlignment.Center;
sfNumberBox.Minimum = 10;
sfNumberBox.Maximum = 30;
sfNumberBox.Value = 50;
Restrict text editing
You can prevent users from editing the numerical value in the editor using the IsEditable property to False. However, you can still change the value by using the up-down buttons, mouse scroll, keyboard arrows, and page keys. By default, the value of IsEditable property is false.
<editors:SfNumberBox x:Name="sfNumberBox"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsEditable="True" />SfNumberBox sfNumberBox = new SfNumberBox();
sfNumberBox.HorizontalAlignment = HorizontalAlignment.Center;
sfNumberBox.VerticalAlignment = VerticalAlignment.Center;
sfNumberBox.IsEditable = true;