WPF Window set Focus

2019-02-12 13:06发布

I have a WPF Window which I only create one time and then Show() and Hide() several times. Now I am searching a way to set the focus on a element on each Show(). Where and how can I do this?

2条回答
别忘想泡老子
2楼-- · 2019-02-12 13:07

In WPF there are two main concepts that pertain to focus: keyboard focus and logical focus. Keyboard focus refers to the element that receives keyboard input and logical focus refers to the element in a focus scope that has focus. These concepts are discussed in detail in this overview.

You can probably write you own ShowHide method by including both Window.Show/Hide and element.Focus functionalities in order to handle both in the same method.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-02-12 13:18

Just call Element.Focus() on the element you want to focus.

If you mean bring focus to the window try calling window.Activate()

查看更多
登录 后发表回答