Event for when KeyboardNavigation.TabNavigation Cycle occurs

一笑奈何 提交于 2019-12-20 04:19:06

问题


I have a WPF Popup that has several controls in it. The user can tab through the controls just fine. But when the last control is reached, then tab will move the focus back to the first control in the Popup.

Rather than cycle back to the start, I would like the Popup to close and have focus move to then next control in the Popup's parent.

I have seen the KeyboardNavigation.TabNavigation options, but no matter what I set them to, the focus always cycles (or tabbing is disabled).

Is there a way to get an OnCycle event so I can manually close the Popup?


回答1:


There is no event that tells you when the focus has cycled back around. You could add a handler for PreviewGotKeyboardFocus event on the first control and close the Popup if the last control currently has keyboard focus. But this would also close the popup if the user explicitly clicked from the last control to the first.

I would probably put an invisible control just after your last control in the tab order. So when the user tabs from the last control, the invisible control would get focus and you would know to close the popup.



来源:https://stackoverflow.com/questions/12979030/event-for-when-keyboardnavigation-tabnavigation-cycle-occurs

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