Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:09:30+00:00 2026-05-25T00:09:30+00:00

I have a really strange problem with WPF. A simple window with a button

  • 0

I have a really strange problem with WPF.

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

Here’s the XAML for Windows1.xaml:

<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">
    <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <WebBrowser Name="m_Browser" Focusable="False" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
                Margin="0"/>

    <TextBox Name="m_Text" Grid.Row="1" />
    <Button Name="m_Ok" Content="_Ok" Click="m_Ok_Click" Grid.Row="2" />
  </Grid>
</Window>

And the code behind (just sets the browser content):

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
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  public partial class Window1 : Window
  {
    public Window1()
    {
      InitializeComponent();

      m_Browser.NavigateToString("<textarea cols=\"20\" rows=\"10\"/>");
    }

    private void m_Ok_Click(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("Ok pressed");
    }
  }
}

EDIT: Fixed using this 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
{
  /// <summary>
  /// Interaction logic for Window1.xaml
  /// </summary>
  public partial class Window1 : Window
  {
    public Window1()
    {
      InitializeComponent();

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

      m_Browser.NavigateToString("<textarea cols=\"20\" rows=\"10\"/>");
    }

    private void m_Ok_Click(object sender, RoutedEventArgs e)
    {
      MessageBox.Show("Ok pressed");
    }

    private static void OnAccessKeyPressed(object sender, AccessKeyPressedEventArgs e)
    {    
      if ((Keyboard.Modifiers & ModifierKeys.Alt) != ModifierKeys.Alt) {
        e.Target = null;
        e.Handled = true;
      }
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:09:30+00:00Added an answer on May 25, 2026 at 12:09 am

    According to the following link: AccessKey Pressed Event Raised when pressing access key without ALT mnemonics work in WPF without the need to press the Alt key.

    There is talk in the thread about this being changed in .net 4.0 however that is what I tested it with so It seems it has not been.

    The thread describes a method that could work for you though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across a really strange problem. I have written a simple Deck class
i have a very strange problem, well not really a problem because i've fixed
I am having some strange problem and its really frustating me. I have a
I have a really strange problem with the standard logging module used in django
I have this really strange problem where my entity framework query isn't enumerating correctly.
So this is a really strange problem. I have a Java app that acts
This is a really strange problem I'm seeing in my app. I have an
I have a really strange problem that I can't explain and fix, it is
I have a really strange problem, following attribute of a jsp tag <custom:tag onclick=addBid('<%=
I have a really strange problem with CMSMS - why the hell this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.