I want to call a generic handler function for all textBox on GotFocus and LostFocus.
For GotFocus I could create:
private void GotFocus()
{
TextBox textBox = ((TextBox)FocusManager.GetFocusedElement());
textBox.Text = "";
}
and call it like this:
private void textBox1_GotFocus(object sender, RoutedEventArgs e)
{
//Instead of this in every TextBox
//TextBox textBox = (TextBox)sender;
//textBox.Text = "";
GotFocus();
}
But for LostFocus I can't do the same to get some symetry handler ? Am I obliged to manage the memorization of the control in GotFocus in a private member so as to be able to use it later in LostFocus ?
Aren't there any way to do this more globally by hooking the .NET system and create this missing GetPreviousFocusedElement function ?
I like the Law of Symetry, that's how Physicians discover new laws and I think this principle could also apply in IT.