Accessing WPF control validation rules from code

前端 未结 3 1667
长情又很酷
长情又很酷 2021-02-01 20:36

XAML:

  
      
          
              
                  <         


        
3条回答
  •  有刺的猬
    2021-02-01 21:20

    you need to get the Binding first before you get the rules

        Binding b=  BindingOperations.GetBinding(textboxMin,TextBox.TextProperty);
        b.ValidationRules
    

    else you can have BindingExpression and check for HasError property

     BindingExpression be1 = BindingOperations.GetBindingExpression (textboxMin,TextBox.TextProperty);
    
    be1.HasError
    

提交回复
热议问题