I've been struggling with this for a few days and I couldn't get a clear and simple answer anywhere. Now that I've fixed the problem on my end, I figured I would share.
The approach is about disabling a "Commit" button (Save/Apply/OK/whatever) whenever an error exists in the form.
Basically, I have a form with several different controls (textbox, combobox, checkbox to name a few). All of them are bound to a custom object within my code, that I referenced using "RootGrid.DataContext = myObjectInstance". They also use BindingValidationRules,
so the user is warned that they have wrong data in there. There's plenty of information about how to achieve this on the internet - but the real question mark is: how can I disable a button if there are errors in the form?
First, go ahead and make those control validations work. For example, write a ValidationRule for a textbox to make sure it's only numbers in there, and then another ValidationRule for another textbox that ensures no digits are contained. Once again, google
is full of examples on how to achieve this.
Then, you need to group all of those controls into a BindingGroup. Before doing so, we will design a ValidationRule that will ensure the BindingGroup is free of validation errors:
public class ErrorFreeBindingGroup : ValidationRule
private string _errorMessage;
View Complete Post