Disable shortcuts in TabbedMdiContainerTabControl

Docking/MDI for WPF Forum

Posted 4 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 19.1.0684


we have a problem with a shortcut from the TabbedMdiContainerTabControl.

The control changes the active document when the home or end key are pressed. This interfers with the navigation in other controls, which is why we disabled it. To do so, we handle the key event with a class handler in the application:

EventManager.RegisterClassHandler(typeof(AdvancedTabControl), UIElement.PreviewKeyDownEvent, new RoutedEventHandler(TabControlPreviewKeyDown));

private static void TabControlPreviewKeyDown(object sender, RoutedEventArgs e)
  KeyEventArgs ke = (KeyEventArgs)e;

  if (ke.Key == Key.Home || ke.Key == Key.End)
    e.Handled = true;

However this causes side-effects in other parts, since the event is triggered, even if a tool window is focused and no document event exists. The property 'IsKeyboardFocusWithin' returns true even when a floating tool window is focused.

So, is there another way to disable the home and end key handling of the tab control?

Best regards, Tobias Lingemann.

Comments (1)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Tobias,

TabbedMdiContainerTabControl indirectly inherits the native WPF TabControl, which does look for Home/End in its OnKeyDown.  That being said, as long as a child control of current tab has focus and some control between that and the parent TabControl handles Home/End in OnKeyDown, then the TabControl should never see it.  

Your best options would be either handle Home/End in an OnKeyDown in the controls currently within your tabs (like all edit controls automatically do) or surround your child controls with a control that handles Home/End in an OnKeyDown.  For instance if you have a ScrollViewer near the root of the tab content, it will handle Home/End.  If you don't want to use ScrollViewer, you could make a custom Decorator to handle the keys and put that as the root of your tab child content.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.