Events in WinUI MaskedTextBox
19 Jun 20232 minutes to read
This section provides information about the events available in the WinUI MaskedTextBox control.
ValueChanging Event
The ValueChanging event occurs when the Value property is about to change in the MaskedTextBox control. The MaskedTextBoxValueChangingEventArgs provides the following properties:
- NewValue: Gets the current value of the MaskedTextBox control.
- OldValue: Gets the previous value of the MaskedTextBox control.
- IsValid: Gets or sets a boolean value indicating whether the input is considered valid based on the mask completion.
- Cancel: Gets or sets a value indicating whether the event should be canceled.
private void MaskedTextBox_ValueChanging(object sender, MaskedTextBoxValueChangingEventArgs e)
{
// Access the new and old values
string newValue = e.NewValue;
string oldValue = e.OldValue;
// Check the validity of the input
bool isValid = e.IsValid;
// Cancel the event if needed
if (newValue == "1234")
{
e.Cancel = true;
}
// Perform additional actions based on the value changing
// ...
}
ValueChanged Event
The ValueChanged event occurs when the Value property is changed in the MaskedTextBox control. The MaskedTextBoxValueChangedEventArgs provides the following properties:
- IsMaskCompleted: Gets a boolean value indicating whether all the required inputs for the mask are completed.
- NewValue: Gets the current value of the MaskedTextBox control.
- OldValue: Gets the previous value of the MaskedTextBox control.
private void MaskedTextBox_ValueChanged(object sender, MaskedTextBoxValueChangedEventArgs e)
{
// Access the new and old values
string newValue = e.NewValue;
string oldValue = e.OldValue;
// Check if the mask input is completed
bool isMaskCompleted = e.IsMaskCompleted;
// Perform actions based on the value change
// ...
}