开发者

How can I set the initially focused element without activating the window (WPF)?

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 netwo开发者_StackOverflow社区rk). 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜