I am validating the data entered in a TextBox when it looses the Focus. When my validation rule identifies the contents of a TextBox as invalid I would like to automatically return the Focus back to the TextBox. My reasoning is that if the user has to reenter valid data I can save him a keystroke by prepositioning the cursor for them.
I pass the name of the TextBox through to the validation class like so ...
<TextBox x:Name="addAnInteger">
<Binding.ValidationRules>
<local:ValidateInteger32 TextBoxName="addAnInteger"/>
</Binding.ValidationRules>
</TextBox>
In the validation class (ValidateInteger32) I have:
public string TextBoxName { get; set; }
The property TextBoxName receives and stores the name of the TextBox that I want to reset the Focus to.
How can I set the Focus back to the "addAnInteger" TextBox from inside the ValidateInteger32 validation class using only the name of the property TextBoxName? I'm thinking something like ....
[Commands that expose the contents of TextBoxName].Focus();
I don't want to use the name of individual TextBoxes in the validation class because I want the class to be generic.
Grateful for any advice.