I have a window with a TextBox and a Button. I want to always focus my TextBox, but allow the user to click the button. How can I do it?
I tried it by using a LostFocusEvent, that whould check who has the focus, and if it wasn't the Button it would focus the TextBox back, but I always get a System.StackOverflowException...
This what I was using:
private void TextLostFocus(object sender, RoutedEventArgs e)
{
IInputElement focusedControl = FocusManager.GetFocusedElement(this);
if (focusedControl != btn && focusedControl != txt)
{
txt.Focus();
}
}
Is there a way to do this?