views:

59

answers:

1

Hi !

I've got problem with keyboard focus. This is how it works now (not correctly):

  1. TextBox
  2. MyControl
  3. if MyControl.PopupShowed then GOTO 1. else GOTO 4.
  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));
+1  A: 

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;
        }
    }
Alex