WPF Window set Focus

自闭症网瘾萝莉.ら 提交于 2019-11-29 18:02:52

问题


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?


回答1:


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.




回答2:


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

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



来源:https://stackoverflow.com/questions/6395645/wpf-window-set-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!