Contents
- ValueChanging Event
- ValueChanged Event
Having trouble getting help?
Contact Support
Contact Support
Events in WinUI Masked TextBox
19 Dec 20232 minutes to read
This section provides information about the events available in the WinUI Masked TextBox control.
ValueChanging Event
The ValueChanging event occurs when the Value property is about to change in the Masked TextBox control. The MaskedTextBoxValueChangingEventArgs provides the following properties:
- NewValue: Gets the current value of the Masked TextBox control.
- OldValue: Gets the previous value of the Masked TextBox 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 Masked TextBox 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 Masked TextBox control.
- OldValue: Gets the previous value of the Masked TextBox 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
// ...
}