I have set IsTabStop
to false on all controls in my window, so that when I press the Tab key, the focus doesn\'t move (I need the Tab key for something else). B
On your window (or some ancestor of the controls you don't want tab to work on) swallow the tab key.
You can swallow it by attaching to the PreviewKeyDown event and set e.Handled = true when the key is a tab.
Pure Code Behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.PreviewKeyDown += MainWindowPreviewKeyDown;
}
static void MainWindowPreviewKeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Tab)
{
e.Handled = true;
}
}
}
You can also set a Keyboard handler as such:
but you'll need a corresponding event handler:
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab)
{
e.Handled = true;
}
}