We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to customize NumericTextBox Background and ForeGround color

Platform: Xamarin.Forms |
Control: SfNumericTextBox |
Published Date: March 23, 2017 |
Last Revised Date: July 4, 2019

We can customize the background and foreground color of numericTexBox control by using “BackgroundColor and TextColor” properties. The following steps illustrate the way to set the background and foreground color of numericTextBox

 

Step 1: Add needed assemblies for NumericTextBox

Step 2: Create a NumericTextBox instance with needed properties.

Step 3: Set the “BackgroundColor “, “TextColor “properties value for customize the view of NumericTextBox

 

The following code illustrates the way to set the background and foreground color of numericTextBox

 

Code in Xaml :

 

<?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="50"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
      <Label x:Name="firstNumeric"  Text="NumericTextBox" FontSize="20" HorizontalOptions="Center"  FontAttributes="Bold" HorizontalTextAlignment="Start" VerticalTextAlignment="Start"/>
      <Synfusion:SfNumericTextBox 
            Grid.Row="1"
            WidthRequest="280" 
            ParserMode="Decimal" 
            HorizontalOptions="Center"  
            MaximumNumberDecimalDigits="2" 
            AllowNull="true" 
            BackgroundColor="Maroon"
            TextColor="White"
            Value="1000"    
            x:Name="sfNumericTextBox"
            FormatString="c" 
            ValueChangeMode="OnKeyFocus" 
            PercentDisplayMode="Value"
              />
        </Grid >
</ContentPage.Content>
</ContentPage>

 

Code in C#:

 

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(50) });
        grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(40) });
        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 = 280,
            ParserMode = Parsers.Decimal,
            HorizontalOptions = LayoutOptions.Center,
            MaximumNumberDecimalDigits = 2,
            AllowNull = true,
            BorderColor = Color.Blue,
            FormatString = "c",
            //background and text color setting code 
            BackgroundColor = Color.Maroon,
            TextColor = Color.White,
            Value = "1000",
            ValueChangeMode = ValueChangeMode.OnKeyFocus,
            PercentDisplayMode = PercentDisplayMode.Value
        };
        grid.Children.Add(firstNumeric, 0, 0);
        grid.Children.Add(sfNumericTextBox, 0, 1);
        this.Content = grid;
    }
}
}
 

 

SfNumericTextBox Background and Foreground Color

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon