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

前端 未结 10 2053
眼角桃花
眼角桃花 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:32

    int count = 0;
    
    private void LayoutRoot_BindingValidationError(object sender, ValidationErrorEventArgs e)
    {
        if (e.Action == ValidationErrorEventAction.Added)
        {
            button1.IsEnabled = false;
            count++;
        }
        if (e.Action == ValidationErrorEventAction.Removed)
        {                
            count--;
            if (count == 0) button1.IsEnabled = true;
        }
    }
    

提交回复
热议问题