'WPF Textbox Validation Error binded to Variable

In a .xaml file, I have a number of Textbox objects that are linked to data paths as such:

<TextBox Text="{Binding Path=Var1}">

These variables (like Var1) are all linked to double values, and as such, if a user attempts to input a non-double value like a string or an empty value, the box is highlighted red. I assume this is the default validation error.

I'd like to know if it's possible to set a boolean to true in my code-behind whenever one of these Textbox objects are highlighted red, and then set back to false when it's not highlighted red. In other words, I'd want to set the boolean to true whenever a user causes the default Textbox validation error, and to false when the error is resolved.

Additionally, I notice that this validation error fires off when the Textbox loses focus; i.e. when the user clicks off of that Textbox or moves to a different Textbox. Is it possible for the validation error to fire off on each keystroke instead?

Thanks. I'm something of a WPF beginner, but it's been hard to find specifics about my issue, and I suspect it'll be useful information to understand data validation down the road.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source