I can't figure out exactly when, but a ChildWindow will somehow .Focus() itself, after the constructor and after the ChildWindow_Loaded event. This was driving me crazy. I'd focus my TextBox in the Loaded event, see the cursor blink once, and then vanish.
So here's a clunky hack to get around it:
private bool firstFocus = true;
//...
private void ChildWindow_GotFocus(object sender, RoutedEventArgs e)
{
if (firstFocus)
{
textBox1.Focus();
firstFocus = false;
}
}
Credit where credit is due.
No comments:
Post a Comment
Speak your mind.