Event for when KeyboardNavigation.TabNavigation Cy

2020-02-15 06:10发布

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条回答
▲ chillily
2楼-- · 2020-02-15 06:57

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.

查看更多
登录 后发表回答