具有WebBrowser控件的WPF TabControl加速键

时间:2018-04-12 20:19:31

标签: wpf wpf-controls webbrowser-control tabcontrol shortcut-key

我有一个设置了加速键的WPF TabControl - 所以用户可以通过按A,B,C和D(不按Alt!)切换到任何Tab。 第三个选项卡包含WebBrowser,如果用户在此Web浏览器的字段中键入任何与Tab的加速键相符的字母,则会切换到另一个Tab而不是在Google搜索字段中键入:
enter image description here

有什么方法可以避免这种情况吗?

1 个答案:

答案 0 :(得分:0)

找到了一个简单的解决方案。
仅当我们从标题为“ Tab_B”的AccessKeyPressed切换到TabItems并将EventArgs句柄附加到所有TabItem并更改<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> 的作用域。

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;
}

处理程序:

// Retrieve the system user ID of the user to impersonate.
OrganizationServiceContext orgContext = new OrganizationServiceContext(_serviceProxy);
_userId = (from user in orgContext.CreateQuery<SystemUser>()
          where user.FullName == "Something from your token" //perhaps domain name?
          select user.SystemUserId.Value).FirstOrDefault();

// To impersonate another user, set the OrganizationServiceProxy.CallerId
// property to the ID of the other user.
_serviceProxy.CallerId = _userId;