WPF KeyboardFocus Popup issue
I've got problem wi开发者_如何学Cth keyboard focus. This is how it works now (not correctly):
- TextBox
- MyControl
- if MyControl.PopupShowed then GOTO 1. else GOTO 4.
- ComboBox
I want by Popup Close to continue with the last tab focus, that means jump from 3 to 4.
How could I do that, please?
<Window>
...
<TextBox />
<MyControl>
...
<Popup>
</Popup>
</MyControl>
<ComboBox />
...
</Window>
FocusableProperty.OverrideMetadata(typeof(ListPicker), new FrameworkPropertyMetadata(true));
Here is one way to do this sort of thing. If it doesn't quite fit your case, you could probably tweak it to fit your needs. Set up an event handler for key down (maybe on the window). If you find that the event is being handled when you press the tab key, then use a preview key down.
internal void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab && MyControl.PopupShowed)
{
MyControl.ClosePopup()
window.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
e.Handled = true;
}
}
精彩评论