WPF TabControl和Tabitem中的加速键问题 [英] Accelerator Key problem in WPF TabControl and Tabitem

查看:178
本文介绍了WPF TabControl和Tabitem中的加速键问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用一个wpf TabControl,其中我有几个TabItems,我将显示文本属性添加到带有助记符的TabItem。但是在TabItem中我在TabContent中有WebBrowser控件。



问题是,当按下webbrowser的页面文本框中的某个键时,它会触发加速键并导航到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...


<tabcontrol>

<tabitem displaytext="_Veritas"></tabitem>

<tabitem displaytext="_Zeus"></tabitem>

<tabitem displaytext="_Sparta"></tabitem>

</tabcontrol>









在Sparta TabItem我有一个web浏览器控件,让我说我有一个谷歌搜索页面...当按下键V或Z分别导航到选项卡Veritas或Zeus而不按Alt键。所以我无法有效地输入谷歌搜索文本框。



如何限制这个?



谢谢和问候

PMM:)





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 :)

推荐答案

这是完美的接受的行为,不应阻止访问任何其他控件。行为但是,你需要解决标签中使用的关键字符(前缀为_)。



请理解,没有奇迹这样的事情。想象一下,你想要 Alt + Z 来激活Zeus,并且 Z 来选择同一 TabControl 中的其他选项卡时,选择Zeus。这是标准和预期的行为。同时,你需要 Alt + Z 或Z来集中控制像文本框一样,你应该明白计算机无法让你知道真实意图:你应该选择聚焦控件和选项卡。



让我在XAML示例中说明这一点:



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>





(顺便说一句:你为​​什么要发布不编译的代码?我知道一个原因:你不能使用<>在HTML中,应该用HTML字符实体替换它们,但为什么displaytext?)



上面的代码完美无缺:你有 Alt + Z Alt + S Alt + V Alt + A 在标签之间导航。如果其中一个选项卡不仅被选中,但 TabControl 也被关注(知道选择和聚焦之间的区别!),你也可以只使用 Z S V 用于选项卡选择。



但是,如果用让我们测试_Z替换_Access文本框,你将失去Alt + Z对文本框聚焦的影响,因为这个键击将改变标签选择(如果文本框被聚焦,这也会间接地转移焦点,因为它变得不可见)。根据用户的需要,你不能指望相同的击键做不同的事情:-)。



如果你认为选项卡选择的移动动作是与关注搜索模式编辑框相比,关键笔划是多余的或不太重要,请再想一想。这是非常合乎逻辑的标准行为。如果您设法修改它,则只会使用户感到困惑。最好的解决方案是找到使用_前缀的准确字符集。



当然,您可以通过删除来禁用按键上的选项卡选择_在冲突字符之前的前缀,但我不推荐它。如果您通过键盘提供逻辑标准导航,只需通过键盘即可快速访问所有控件,即可实现最佳UI设计。应该避免任何不直观明显的组合键。



-SA



(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 :-).

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


我解决了它通过添加一个事件处理程序和



I solved it by adding a eventhandler and

<window x:class="TabTest.MainWindow" xmlns:x="#unknown"><br />
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
        Title="MainWindow" Height="350" Width="525"<br />
         AccessKeyManager.AccessKeyPressed="AccessKeyPressed"></window>





并处理所有没有alt修饰符的事件。





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

        <br />
private void AccessKeyPressed(object sender, AccessKeyPressedEventArgs e) {<br />
                if ((Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt) {<br />
                    e.Target = null;<br />
                    e.Handled = true;<br />
                }<br />
        }


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.


这篇关于WPF TabControl和Tabitem中的加速键问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆