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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind value in NumerictextBox?

To bind the value in NumericTextBox, follow the given steps:

Step 1: Create the NumericTextBox sample and include the necessary source files.

Step 2: Create an instance for ViewModel and NumericTextBox.

Step 3: Set the BindingContext to ViewModel.

Step 4: The ViewModel class extends INotifyPropertyChanged and it gets and sets the value.

Step 5: Now SetBinding for the NumericTextBox instance created. The parameters in Binding will have the ValueProperty and where the value is binded and it specifies the binding mode.

 

//NumericTextBox class

 

public class NumericTextBox : ContentPage

{

    public NumericTextBox ()

   {

         Label label1 = new Label ();

         label1.Text = "Monetary";

         ViewModel viewModel = new ViewModel ();

          var textBox = new SfNumericTextBox()

          {

                                HorizontalOptions = LayoutOptions.FillAndExpand,

                                FormatString = "c",

                                MaximumNumberDecimalDigits = 2                                               

                };

                textBox.BindingContext = viewModel;

                textBox.SetBinding(SfNumericTextBox.ValueProperty,"Value", BindingMode.TwoWay);

 

            StackLayout stack = new StackLayout ();

                stack.Orientation = StackOrientation.Vertical;

                stack.Children.Add (label1);

                stack.Children.Add (textBox);

         

            this.Content = stack;

  }

}

 

//ViewModel class

 

public class ViewModel : INotifyPropertyChanged

{

                public event PropertyChangedEventHandler PropertyChanged;

                public ViewModel ()

                {

                }

                private float _value=5;

 

                public float Value

           {

                get{ return _value;}

                set{_value = value;RaisePropertyChanged ();}

            }

 

            protected void RaisePropertyChanged([CallerMemberName]string propertyName = "")

                {

                if (this.PropertyChanged != null)

                {

                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

                }

           }

}

 

 

Article ID: Published Date: Last Revised Date: Platform: Control:
7064 08/26/2016 08/26/2016 Xamarin.Forms SfNumericTextBox
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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