gpt4 book ai didi

c# - Lync ContactList WPF 控制热键/快捷键从 WebBrowser 窃取按键

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:04 27 4
gpt4 key购买 nike

问题

Lync 有一些热键/快捷键用于更改联系人列表控件中的选项卡。这些热键是“g”、“s”和“r”。当我按下这些键中的任何一个时,同时将 HTML 输入控件聚焦在任何网页上的 WebBrowser 内,按键将转到 ContactList 控件而不是 WebBrowser 控件。在浏览器外部的控件(如 WPF TextBox 控件)中键入时,不会窃取按键。

重现问题的步骤

  1. 安装了 Microsoft Lync 2013
  2. http://www.microsoft.com/en-au/download/details.aspx?id=36824 下载并安装 Microsoft Lync 2013 客户端 SDK
  3. 创建 .net 4.0 wpf 应用程序。将 ContactList 控件拖放到 MainWindow 中,以便它自动设置引用和命名空间
  4. 将以下代码粘贴到 MainWindow.xaml 的 Window 元素中

    <Window...
    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="auto" />
    <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <controls:ContactList Name="contactList1" Grid.Column="0" />
    <WebBrowser Grid.Column="1" Source="http://www.google.com" />
    </Grid>

  5. 在 google 搜索框中按“r”、“g”或“s”键,注意按键是如何转到 lync 控件而不是搜索框的。任何其他键都正常工作。

我尝试过的事情

我试图阻止键事件冒泡到 ContactList 控件。然而,我在这方面并没有取得太大的成功。

disable event-bubbling c# wpf

WPF prevent event bubbling outside of a control

最佳答案

在这里找到答案:AccessKey Pressed Event Raised when pressing access key without ALT

出现此行为是因为 WPF 不需要按住 alt 键来使 AccessKeys 起作用。与 WinForms 一样。在这种情况下,从 WebBrowser 中按“g”、“s”或“r”会聚焦 ClientControl,但我只希望在按住 alt 时发生这种情况。我不知道为什么这个问题似乎只发生在 WebBrowser 上。

来自 msdn 链接:

We have defined an access key on a label, which gives focus to a textbox.

We have a second readonly textbox on the same user control.

When clicking inside the readonly textbox and pressing the access key without ALT (e.g. L instead of ALT + L) the focus change is done anyway.

Is it possible to disable this behaviour, i.e. is it possible to ensure, that the access key is only working when pressed together with ALT?

The following xaml shows the issue:

<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="Height"
Width="300" WindowStartupLocation="CenterScreen">
<StackPanel Orientation="Vertical">
<TextBox IsReadOnly="True" Text="ReadOnly - give focus and press l" />
<Label Content="_Label:" Target="{Binding ElementName=box}"/>
<TextBox x:Name="box" />
</StackPanel>
</Window>

解决方案

Menu and ToolBar menmonics work without pressing Alt key. We decided that we will have uniform behavior in all cases so access key work withour pressing Alt key.

I understand that this is not in parity with Forms and we will consider this issue and change the behavior in the next version.

For now as a workaround you can redister a class handler for all AccessKeyPressed events and handle the event if Alt key is not pressed.

EventManager.RegisterClassHandler(typeof(UIElement), AccessKeyManager.AccessKeyPressedEvent, new AccessKeyPressedEventHandler(OnAccessKeyPressed));

private void OnAccessKeyPressed(object sender, AccessKeyPressedEventArgs e)
{
if (!e.Handled && e.Scope == null && (e.Target == null || e.Target == label))
{
// If Alt key is not pressed - handle the event
if ((Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt)
{
e.Target = null;
e.Handled = true;
}
}
}

我将解决方案代码添加到 MainWindow 类,一切都按预期工作。

关于c# - Lync ContactList WPF 控制热键/快捷键从 WebBrowser 窃取按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16329452/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com