0

I've a WPF TabControl with acceleration keys set - so user can switch to any Tab by hitting A, B, C and D (without pressing Alt!).
Third Tab contains WebBrowser and if user type in the field of this web browser any letter which coincide with Tab's acceleration keys it switches to another Tab instead of typing in the Google search field:
enter image description here

Is there any way to avoid this?

IgorStack
  • 799
  • 2
  • 6
  • 22

1 Answers1

0

Found an easy solution.
Attach AccessKeyPressed hander to all TabItems and change EventArgs scope there only if we switch from TabItem with header "Tab_B".

<TabControl>
    <TabItem Header="Tab_A" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed"/>
    <TabItem Header="Tab_B" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed">
        <WebBrowser Source="http://google.com"  />
    </TabItem>
    <TabItem Header="Tab_C" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed"/>
    <TabItem Header="Tab_D" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed"/>
</TabControl>

Handler:

private void TabItem_AccessKeyPressed(object sender, AccessKeyPressedEventArgs e)
{
    var src = ((sender as TabItem)?.Parent as TabControl)?.SelectedItem as TabItem;
    if (src?.Header as string == "Tab_B")
        e.Scope = src;
}
IgorStack
  • 799
  • 2
  • 6
  • 22