Click here to Skip to main content
12,075,066 members (65,004 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: WPF
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...


<tabcontrol>
 
<tabitem displaytext="_Veritas"></tabitem>
 
<tabitem displaytext="_Zeus"></tabitem>
 
<tabitem displaytext="_Sparta"></tabitem>
 
</tabcontrol>



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 | :)
Posted 29-Mar-11 20:01pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This is perfectly accepted behavior which should not prevent access to any other control. The behavior However, you need to resolve key characters (prefixed with "_") used in labels.

Please understand, there is no such thing as miracle. Imagine that you want "Alt+Z" to activate "Zeus" when it is visible, and "Z" to select "Zeus" when some other tab in the same TabControl is selected. This is standard and expected behavior. Is, at the same time, you need "Alt+Z" or "Z" to focus some control like a text box, you should understand that a computer cannot know you real intent: you should choose between focusing a control and selection of the tab.

Let me illustrate this on a XAML sample:

<TabControl>
   <TabItem header="_Veritas">
      <DockPanel LastChildFill="True">
         <Label
             Target="{Binding ElementName=tb}"
             DockPanel.Dock="Top">_Access text box:</Label>
         <TextBox name="tb"></TextBox>
      </DockPanel>
   </TabItem>
   <TabItem header="_Zeus"></TabItem>
   <TabItem header="_Sparta"></TabItem>
</TabControl>

(By the way: why would you post code which does not compile? I know one reason: you cannot use <> in HTML, should replace them with HTML character entities, but why "displaytext"?)

The code above works perfectly: You have Alt+Z, Alt+S, Alt+V and Alt+A to navigate between tabs. If one of the tabs is not only selected but the TabControl is also focused (know the difference between selection and focusing!), you can also use just "Z", "S", or "V" for tab selection.

However, if you replace "_Access text box" with "Let's test _Z" you will loose the effect of "Alt+Z" on focusing of the text box, because this key stroke will shift tab selection (this is also indirectly shifts focus if the text box was focused, because it gets invisible). You cannot expect the same key stroke to do different things depending on what the user wants Smile | :) .

If you think that the action of shifting of the tab selection by a key stroke is redundant or less important compared to focusing on search pattern edit box, think again. This is very logical and standard behavior. If you manage to modify it, you only confuses the user. The best solution is finding the accurate set of the characters used the the "_" prefix.

Of course, you can disable tab selection on keystroke simply by removing the "_" prefix before the "conflicting" character, but I would not recommend it. You can achieve the best UI design if you provide logical standard navigation via keyboard with really quick access to all the control via just the keyboard. Any key combinations which are not intuitively obvious should be avoided.

—SA
  Permalink  
v7
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I think you are not getting what I want?
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

I solved it by adding a eventhandler and


xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
AccessKeyManager.AccessKeyPressed="AccessKeyPressed">


and handle all events which don't have a alt modifier.

private void AccessKeyPressed(object sender, AccessKeyPressedEventArgs e) {
if ((Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt) {
e.Target = null;
e.Handled = true;
}
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi, Engelhadt672

It Works cool. Brilliant.

Thanks.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Hi,
 
 I tried this solution with my application , it works with single underscore like  'test_1'
 
But if i put two underscore like 'test__1' in tab name , it only displays one underscore. For three underscore it displays two underscore.
 
please help me out.
  Permalink  
Comments
CHill60 1-Feb-16 10:24am
   
If you have a question of your own then use the "Ask a Question" link. Alternatively use the "Have a Question or Comment" link next to a solution so that the poster is notified of your response.
Don't post questions or comments as solutions to old posts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 31 Jan 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100