0

I have implemented custom validator as following...

 public class RquiredFiledValidation:ValidationRule
{
    public string ErrorMessage { get; set; }

    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        if (string.IsNullOrWhiteSpace(value.ToString()))
            return new ValidationResult(false, ErrorMessage);
        else
            return new ValidationResult(true, null);
    }
}

And Attached this with a text box as following...

 <TextBox x:Name="txtLoging" Grid.Column="1" HorizontalAlignment="Stretch" Validation.ErrorTemplate="{x:Null}" VerticalAlignment="Center"  Margin="0,40,30,0">
        <Binding Path="Text" ElementName="txtLoging" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True">
            <Binding.ValidationRules>
                <Validate:RquiredFiledValidation  ErrorMessage="Please Provide Login Name"></Validate:RquiredFiledValidation>
            </Binding.ValidationRules>
        </Binding>
    </TextBox>

My problem is...

1) When I click directly on login button then the validation doesn't get fired

2) When I put a character in text box validation get fired but produced stack overflow error.

7
  • When I changed UpdateSourceTrigger="LostFocus" It stop working. Commented Dec 22, 2016 at 6:56
  • How you are showing the error? Do you have any style or validation.ErrorTemplate for that? Provide the stack overflow error details. Commented Dec 22, 2016 at 8:37
  • Yes, i have control template defined in resource for error template. I have solved the second problem. But first problem is still there. And i have encounter with another problem that is error message is getting overlapped with other control. Commented Dec 22, 2016 at 8:44
  • Any help on first question..When i click directly on login button then the validation doesn't get fired Commented Dec 22, 2016 at 9:11
  • Are you using MVVM? Commented Dec 22, 2016 at 9:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.