Articles in this section
Category / Section

How to create Numeric TextBox sample in Xamarin.Forms and Android?

1 min read

Xamarin.Forms Numeric TextBox is an advanced version of the Entry control that restricts input to numeric values. The below illustrates how to create the NumericTextBox control in Xamarin.Forms Android platforms.

Needed assemblies:

For getting the view of NumericTextBox control, need to add the following assemblies in both PCL and android in Xamarin.

 

Project

Assemblies Required

PCL

pcl\Syncfusion.SfNumericTextBox.XForms.dll

 

Android

android\Syncfusion.SfNumericTextBox.Android.dll
android\Syncfusion.SfNumericTextBox.XForms.Android.dll
android\Syncfusion.SfNumericTextBox.XForms.dll

 

 

Code Snippet

C# Code

 

namespace KBSolution
{
public partial class KBSolutionPage : ContentPage
{
    public KBSolutionPage()
    {
        InitializeComponent();
 
        Grid grid = new Grid() { BackgroundColor = Color.FromHex("E4EAF0") };
        grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
        grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50) });
 
        Label firstNumeric = new Label()
        {
            Text = "NumericTextBox",
            FontSize = 20,
            HorizontalOptions = LayoutOptions.Center,
            FontAttributes = FontAttributes.Bold,
            HorizontalTextAlignment = TextAlignment.Start,
            VerticalTextAlignment = TextAlignment.Start
        };
        SfNumericTextBox sfNumericTextBox = new SfNumericTextBox()
        {
            WidthRequest = 180,
            ParserMode = Parsers.Decimal,
            HorizontalOptions = LayoutOptions.Center,
            MaximumNumberDecimalDigits = 2,
            AllowNull = true,
            BorderColor = Color.Blue,
            TextColor = Color.Maroon,
            Value = 1000,
            FormatString = "c",
            ValueChangeMode = ValueChangeMode.OnKeyFocus,
            PercentDisplayMode = PercentDisplayMode.Value,
            FontSize = 20
 
        };
        grid.Children.Add(firstNumeric, 0, 0);
        grid.Children.Add(sfNumericTextBox, 0, 1);
        this.Content = grid;
    }
}
}

 

XAML Code

 

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      xmlns:local="clr-namespace:KBSolution"
      xmlns:Synfusion="clr-namespace:Syncfusion.SfNumericTextBox.XForms;assembly=Syncfusion.SfNumericTextBox.XForms"
      x:Class="KBSolution.KBSolutionPage">
  <ContentPage.Content>
      <Grid  BackgroundColor="#E4EAF0">
          <Grid.RowDefinitions>
              <RowDefinition Height="30"/>
              <RowDefinition Height="50"/>
          </Grid.RowDefinitions>
            <Label x:Name="firstNumeric" Text="NumericTextBox" FontSize="20" HorizontalOptions="Center"  FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="Start"/>
            <Synfusion:SfNumericTextBox 
              Grid.Row="1"
              WidthRequest="180" 
              ParserMode="Decimal" 
              HorizontalOptions="Center"  
              MaximumNumberDecimalDigits="2" 
              AllowNull="true" 
              BorderColor="Blue" 
              TextColor="Maroon" 
              x:Name="sfNumericTextBox"
              Value="1000" 
              FormatString="c" 
              ValueChangeMode="OnKeyFocus" 
              PercentDisplayMode="Value"
              FontSize="20" />
          </Grid >
  </ContentPage.Content>
</ContentPage>

 

Create SfNumericTextBox

 

Conclusion

I hope you enjoyed learning how to create Numeric TextBox sample in Xamarin.Forms and Android.

You can refer to our Xamarin. Forms Numeric TextBox feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Xamarin. Forms Numeric TextBox example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


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