- public void ValidateTextbox(ref TextBox ctrltxt, string p)
- {
- int count = 0;
- string errormessage=string.Empty;
- BindingExpression expression = ctrltxt.GetBindingExpression(TextBox.TextProperty);
- expression.UpdateSource();
- if (true) // check validation condition or reg expression here
- {
- ValidationError error = new ValidationError(new ExceptionValidationRule(), expression, errormessage, null);
- Validation.MarkInvalid(expression, error);
- }
- }
XAML code for the TEXTBOX is as below
- <TextBox Name="FieldName" HorizontalAlignment="Stretch"
- VerticalAlignment="Stretch"
- Text="{Binding Path=DisplayData, ValidatesOnDataErrors=True ,NotifyOnValidationError=True , UpdateSourceTrigger=LostFocus, ValidatesOnExceptions=True}"
- Grid.Column="1"
- Margin="4,4,4,4" Validation.ErrorTemplate="{StaticResource InputErrorTemplate}" >
- </TextBox>
InputErrorTemplate is as below
Join the conversation! Your thoughts help the community grow.