Accelerator Key problem in WPF TabControl if a web browser control is inside a tabitem...


  • Hi All,

    I am using a wpf TabControl, in which I have several TabItems and I added the Display Text property to the TabItem with mnemonics. But In a TabItem am having WebBrowser Control in the TabContent.

    The problem is, while pressing a key in the webbrowser's page textbox, it triggers the accelerator key and navigating to the tabitem. For Example, See the code below...

    <tabitem Header="_Veritas"><webbrowser name="wbVeritas"> </tabitem>
    <tabitem Header="_Zeus"><webbrowser name="wbZeus"></tabitem>
    <tabitem Header="_Sparta"><webbrowser name="wbSparta"></tabitem>

    In Sparta TabItem I have a webbrowser control and lets say I have a google search page in it... While am pressing the key V or Z its navigating to the tab Veritas or Zeus respectively with out pressing Alt Key. So I could not able to type in the google search textbox effectively.

    How can I restrict this?

    Thanks and Regards
    PMM Smile | :)

    Thursday, March 31, 2011 6:24 AM


  • Hi PeerMohamedMydeen,

    I think you could achieve what you need by handling the AccessKeyManager.AccessKeyPressed method, something should be like below code show:


    <Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
       <TabItem Header="_Veritas" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed">
        <WebBrowser Name="wbVeritas">
       <TabItem Header="_Zeus" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed_1">
        <WebBrowser Name="wbZeus"/>
       <TabItem Header="_Sparta" AccessKeyManager.AccessKeyPressed="TabItem_AccessKeyPressed_2">
        <WebBrowser Name="wbSparta" Source="http:\\"/>

    Code behind:

      private void TabItem_AccessKeyPressed(object sender, AccessKeyPressedEventArgs e)
       e.Scope = sender;
      private void TabItem_AccessKeyPressed_1(object sender, AccessKeyPressedEventArgs e)
       e.Scope = sender;
      private void TabItem_AccessKeyPressed_2(object sender, AccessKeyPressedEventArgs e)
       e.Scope = sender;

    I think the reason is system can't tell which the proper key to handle is. As you can see, I set the AccessKeyScope for each control to its own. So the shortcut key won't be triggered unless the control has focus.

    Hope this may meet your requirement.

    If you still have any concerns please feel free to let me know.

    Best regards

    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 04, 2011 3:39 PM