Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF WebBrowser fires button shortcut as ALT+Key is pressed
    primarykey
    data
    text
    <p>I have a really strange problem with WPF.</p> <p>A simple window with a button with a shortcut ("_Ok") and a webbrowser control. The problem is: when the cursor is in a textarea inside the webbrowser when I press "o" wpf fires the button click as I'm pressing Alt+O</p> <p>Here's the XAML for Windows1.xaml:</p> <pre><code>&lt;Window x:Class="testBrowser.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;WebBrowser Name="m_Browser" Focusable="False" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0"/&gt; &lt;TextBox Name="m_Text" Grid.Row="1" /&gt; &lt;Button Name="m_Ok" Content="_Ok" Click="m_Ok_Click" Grid.Row="2" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>And the code behind (just sets the browser content):</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace testBrowser { /// &lt;summary&gt; /// Interaction logic for Window1.xaml /// &lt;/summary&gt; public partial class Window1 : Window { public Window1() { InitializeComponent(); m_Browser.NavigateToString("&lt;textarea cols=\"20\" rows=\"10\"/&gt;"); } private void m_Ok_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Ok pressed"); } } } </code></pre> <p>EDIT: Fixed using this code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace testBrowser { /// &lt;summary&gt; /// Interaction logic for Window1.xaml /// &lt;/summary&gt; public partial class Window1 : Window { public Window1() { InitializeComponent(); EventManager.RegisterClassHandler(typeof(UIElement), AccessKeyManager.AccessKeyPressedEvent, new AccessKeyPressedEventHandler(OnAccessKeyPressed)); m_Browser.NavigateToString("&lt;textarea cols=\"20\" rows=\"10\"/&gt;"); } private void m_Ok_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Ok pressed"); } private static void OnAccessKeyPressed(object sender, AccessKeyPressedEventArgs e) { if ((Keyboard.Modifiers &amp; ModifierKeys.Alt) != ModifierKeys.Alt) { e.Target = null; e.Handled = true; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload