I have a button which is enabled/disabled based on validation.hasError property of few textboxes and it works fine, untill i wanna disable and enable this same button from code behind based on some business logic. for example.
if(recordExist) { btn.IsEnabled=true;} else{ btn.isenabled=false;}
now what happens is that once the else
logic is carried out and the button is disabled, the button is not re-enabled again even if the validation.HasError
of all the controls return false. and like wise if the if
logic is carried out and button is enabled it stays enabled even if the validation.hasError
returns true. what i want is to somehow re-Trigger the multiDataTriggers
to check the Validation.hasError
on the textboxes
and update the isEnabled
property of the button accordingly. i hope i am clear enough.
See Dependency Property Value Precedence on MSDN.
Once you set local value, triggers can't override it. You need to adjust bindings, triggers etc. to take the logic in the code behind into account. If you're using MVVM (and you should), you can add the condition to your view-model.
Alternatively, if you want the control to forget about the local value and let the trigger take precedence, you can use ClearValue
. Or you can use SetCurrentValue
and avoid giving precedence to the new value. However, you should avoid using these functions, they will make your code harder to understand and maintain.