Using WPF Validation rules and the disabling of a 'Save' button

前端 未结 10 2096
眼角桃花
眼角桃花 2020-11-28 09:54

I have a page where a few textboxes cannot be empty before clicking a Save button.


                            


        
10条回答
  •  生来不讨喜
    2020-11-28 10:33

    Because it's still missing, here is an adaption of Developer's answer in case the link ever goes away:

    XAML:

    
        
            
                
                                          
        
    
    

    CodeBehind/C#:

    private int _numberOfValidationErrors;
    public bool HasNoValidationErrors => _numberOfValidationErrors = 0;
    
    private void handleValidationError(object sender, ValidationErrorEventArgs e)
    {
        if (e.Action == ValidationErrorEventAction.Added)
            _numberOfValidationErrors++;
        else
            _numberOfValidationErrors--;
    }
    

提交回复
热议问题