开发者

Binding occurs before Validation

I have a button bounded on Validation.HasError property of a textblock. The textblock has a validation rule that checks the value entered by user. The purpose of the binding is that the button should be disabled if the user enters a wrong data.

The problem is that the ValidationRule executes AFTER the binding. So when the user types a wrong value, the binding checks the HasError property of the textblock, which is FALSE, so the button is Enabled. And then the validationrule executes. It results in a reversed situation where the texblock is invalid and the button is enabled.

How could I specify which (binding and validation) executes first ?

Here's the XAML:

  <MultiBinding Converter="{StaticResource ButtonVisibilityConverter}" UpdateSourceTrigger="PropertyChanged" Mode="OneWay" >
     <Binding ElementName="integerInput" Path="HasVal开发者_Go百科idationError"/>
     <Binding ElementName="doubleInput"  Path="HasValidationError"/>
  </MultiBinding>

</Button.IsEnabled>

I'm sure it isn't the case. The textblock control I'm talking about is a custom spinner (textbox with two +/- buttons). The content of the spinner is bound to a property in the viewmodel. Each time we click on + or - button a command is executed and increments or decrements the value in the textbox.


What XAML are you using to bind the button to the textbox? Any change to the HasError property should trigger the binding to re-evaluate on the button regardless of at what stage validation is performed.

Are you sure your problem isn't that when the HasErrors property is false you want the IsEnabled property to be true and you're not reversing the value in the binding?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜