Articles in this section
Category / Section

How to disable the clear button in numeric textbox in Xamarin.Forms

1 min read

The SfNumericTextBox control is an advanced version of the Entry control that restricts input to numeric values. The cancel button is to clear the entire value in the numeric textbox area as shown in the following image.

 

With close button

 

 

If you want to get rid of disabling the cancel button in Android and iOS, use the ClearButtonVisibility property to achieve your requirement. This property should be set to an enumeration member of ClearButtonVisibilityMode.

 

Never - Indicate control will never display a clear button and the platform default is used.

 

WhileEditing - Indicates that the clear button will be displayed in the numeric textbox, while it has focus and text.

 

This feature is supported by Android version 5.0 (API level 21 or higher) and is not supported on the UWP platform as it already has framework level supports. For getting the same UI as shown in the following UWP.

 

disable close button

Please find the workaround with the custom renderer usage as follows.

 

[C#]

public class CustomNumericTextBox: SfNumericTextBox
{
 
}

 

[XAML]

<StackLayout>
        <local:CustomNumericTextBox Value="123" />
</StackLayout>

 

[CustomNumericTextBoxRenderer_UWP]

    public class CustomNumericTextBoxRenderer : SfNumericTextBoxRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<SfNumericTextBox> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.ShowClearButton = false;
            }
         }
    }

 

View the sample in GitHub

 

See also

How to customize the colors in Xamarin.Forms SfNumericTextBox

How to format the numeric value in Xamarin.Forms SfNumericTextBox

Available interaction in numeric control


 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied