tags:

views:

26

answers:

0

My program creates a window with ShowActivated=false, so that it doesn't steal keyboard focus when it's opened (the window is created in response to events coming over the network). I want to be able to specify that a particular TextBox field receives focus when the user switches to the window. However, the seemingly obvious methods (using FocusManager.FocusedElement in the window's markup, or calling this.textbox.Focus() when the window is shown) have the side effect of activating the window.

I ended up adding an event handler for the window's Activated event, which (a) makes the desired Focus() call, and (b) removes itself from the Activated event, so that it only happens once. This seems crufty. Am I missing something?