comment 0

Weird bug on WinRT land #1

I was looking today at a bug which was affecting the Plex Windows 8 app (WinRT), which caused the tab order to be messed up globally in the app. Eventually I narrowed it down to a Dispatcher.AcceleratorKeyActivated event handler that looked a bit like this:

    void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender,
                                                AcceleratorKeyEventArgs args)
    {
      if (args.EventType == CoreAcceleratorKeyEventType.KeyDown)
        args.Handled = this.HandleKeyDown(args.VirtualKey);
    }

I will save you the details, but the thing causing the problem here is the path of execution where args.Handled gets set to false. In that case, if you don’t leave Handled alone, you incur in a bug which causes the Tab key to be processed twice, so you get the impression your tab order is messed up and that certain controls are not tab stops.

So what you want to do instead is:

    void CoreDispatcher_AcceleratorKeyActivated(CoreDispatcher sender,
                                                AcceleratorKeyEventArgs args)
    {
      if (args.EventType == CoreAcceleratorKeyEventType.KeyDown &&
          this.HandleKeyDown(args.VirtualKey))
      {
          args.Handled = true;
      }
    }

Just another oddity of the WinRT platform…