Events in Xamarin Numeric Entry (SfNumericTextBox)

29 Sep 20233 minutes to read

Value changed event in SfNumericTextBox

You can perform operation while the changing the value of SfNumericTextBox value using ValueChanged event. ValueChanged event returns the changed value in NumericTextBox.

Members Description
Value Displays changed value in NumericTextBox
<syncfusion:SfNumericTextBox 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 in SfNumericTextBox

The ValueChangeMode property is used to mention when the validation should occur, either in key pressed or in focus lost. When ValueChangeMode is set to OnKeyFocus, the validation occurs for each key press. When ValueChangeMode is OnLostFocus, the validation occurs when the control loses focus or moves the focus to the next control. ValueChangeMode includes the following options:

  1. OnKeyFocus
  2. OnLostFocus

OnKeyFocus in SfNumericTextBox

<syncfusion:SfNumericTextBox ValueChangeMode="OnKeyFocus" Value="123" ValueChanged="SfNumericTextBox_ValueChanged" />
SfNumericTextBox numericTextBox=new SfNumericTextBox();
numericTextBox.Value = 123;
numericTextBox.ValueChanged += NumericTextBox_ValueChanged;
numericTextBox.ValueChangeMode = ValueChangeMode.OnKeyFocus;
this.Content=numericTextBox;

private void SfNumericTextBox_ValueChanged(object sender, Syncfusion.SfNumericTextBox.XForms.ValueEventArgs e)
{
    DisplayAlert("OnKeyFocus", e.Value.ToString(), "OK");
}

Display SfNumericTextBox control with ValueChanged event OnKeyFocus

OnLostFocus in SfNumericTextBox

<syncfusion:SfNumericTextBox ValueChangeMode="OnLostFocus" Value="123"  ValueChanged="SfNumericTextBox_ValueChanged" />
SfNumericTextBox numericTextBox = new SfNumericTextBox();
numericTextBox.Value = 123;
numericTextBox.ValueChanged += NumericTextBox_ValueChanged;
numericTextBox.ValueChangeMode = ValueChangeMode.OnLostFocus;
this.Content = numericTextBox;

private void SfNumericTextBox_ValueChanged(object sender, Syncfusion.SfNumericTextBox.XForms.ValueEventArgs e)
{
    DisplayAlert("OnLostFocus", e.Value.ToString(), "OK");
}

Display SfNumericTextBox control with ValueChanged event OnLostFocus

Completed event in SfNumericTextBox

Raised the completed event when the user finalizes the text in the SfNumericTextBox by pressing return key on the keyboard.

<syncfusion:SfNumericTextBox 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