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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to bind value in NumerictextBox?

Platform: Xamarin.Forms |
Control: SfNumericTextBox |
Published Date: August 26, 2016 |
Last Revised Date: October 19, 2021

To bind the value in NumericTextBox using MVVM pattern, follow the given steps:

Step 1:  Create the Xamarin forms sample.

Step 2: Install the NumericTextBox NuGet from nuget.org and include the NumericTextBox namespace.

Step 2: Create a ViewModel class and add a property to bind the Value property in NumericTextBox as mentioned in the below code sample.

[C#]:

//ViewModel class
 
public class ViewModel : INotifyPropertyChanged
{
 public event PropertyChangedEventHandler PropertyChanged;
 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));
   }
           }
}

 

The ViewModel class should extends INofityPropertyChanged, implement its event and raised from Value's property setter as like above snippet, then only we can get the property changing notifications.

Step 3: Set the BindingContext to ViewModel.

[XAML]:

<ContentPage.BindingContext>
    <local:ViewModel />
</ContentPage.BindingContext>

 

Step 4: Initialize the SfNumericTextBox control and bind the value property as shown in the below code sample.

[XAML]:

<ContentPage.Content>
    <StackLayout >
        <syncfusion:SfNumericTextBox x:Name="numericTextBox" 
                                                             Value="{Binding Value, Mode=TwoWay}"
                                                             HorizontalOptions="Center" 
                                                             VerticalOptions="Center" />
    </StackLayout>
</ContentPage.Content>

 

 

 

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Seth Isaacks
Nov 05, 2020

How do you bind with MVVM????????? I have tried MULITPLE time to wind to the VALUE and it displays the value but will NOT update the value

Reply

Please sign in to access our KB

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

Up arrow icon

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

Live Chat Icon For mobile