Events and Interactivity in Xamarin Numeric Entry (SfNumericTextBox)

19 May 20212 minutes to read

Events

ValueChanged

We can perform operation while the changing the value of NumericTextBox’s Value using ValueChanged event. ValueChanged event returns the changed value in NumericTextBox.

Members Description
Value Displays changed value in NumericTextBox
<syncfusion:SfNumericTextBox x:Name="numericTextBox" ValueChanged="Handle_ValueChanged" Value="123"  />
SfNumericTextBox numericTextBox=new SfNumericTextBox();
numericTextBox.Value = 123;
numericTextBox.ValueChanged += Handle_ValueChanged;
this.Content=numericTextBox;

void Handle_ValueChanged(object sender, Syncfusion.SfNumericTextBox.XForms.ValueEventArgs e)
{
    System.Diagnostics.Debug.WriteLine(e.Value.ToString());
}

Interactivity : ValueChangeMode

The ValueChangeMode property is used to mention when the validation need to take place, either in key pressed or in focus lost. When ValueChangeMode is set to OnKeyFocus, the validation will be carried out for each key press. When ValueChangeMode is OnLostFocus, the validation occur when the control lost the focus or the focus move to next control. ValueChangeMode includes the following options:

  1. OnKeyFocus
  2. OnLostFocus

OnKeyFocus

<syncfusion:SfNumericTextBox ValueChangeMode="OnKeyFocus" x:Name="numericTextBox"  Value="123"  />
SfNumericTextBox numericTextBox=new SfNumericTextBox();
numericTextBox.Value = 123;
numericTextBox.ValueChangeMode = ValueChangeMode.OnKeyFocus;
this.Content=numericTextBox;

Display SfNumericTextBox control with ValueChanged event OnKeyFocus

OnLostFocus

<syncfusion:SfNumericTextBox ValueChangeMode="OnLostFocus" x:Name="numericTextBox"  Value="123"  />
SfNumericTextBox numericTextBox=new SfNumericTextBox();
numericTextBox.Value = 123;
numericTextBox.ValueChangeMode = ValueChangeMode.OnLostFocus;
this.Content=numericTextBox;

Display SfNumericTextBox control with ValueChanged event OnLostFocus

Completed

Raised when the user finalizes the text in the NumericTextBox by pressing return key on the keyboard.

<syncfusion:SfNumericTextBox x:Name="numericTextBox" Completed="Handle_Completed”/>
SfNumericTextBox numericTextBox=new SfNumericTextBox();
numericTextBox.Completed += Handle_Completed;
this.Content=numericTextBox;

void Handle_Completed(object sender, System.EventArgs e)
{
  System.Diagnostics.Debug.WriteLine(Completed);         
}

See also

How to change the SfNumericTextBox style using its visual states

How to define and apply a common style for SfNumericTextBox