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

  • Home
  • SEARCH
  • 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 7970967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:31:42+00:00 2026-06-04T07:31:42+00:00

In WPF when you make a label like this: <Label Content=_My Label/> Then when

  • 0

In WPF when you make a label like this:

<Label Content="_My Label"/>

Then when you run the app and press the Alt key it will show the “M” underlined.

We have our own custom hotkey Attached Property that allows us to use Ctrl as well as Alt.

Problem is that only Alt will show the underscores.

Is there a way to show the underscore when the Ctrl key is pressed?

NOTE: I do NOT want to send a programmatic Alt KeyPress in the background when Ctrl is pressed. That will just confuse my shortcut system.

  • 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-06-04T07:31:43+00:00Added an answer on June 4, 2026 at 7:31 am

    Ok! I have got a solution to show the _ for hot-keys without Alt pressed but Ctrl pressed.

    Here is how to Do it :


    Small Code to Press a KeyBoard Key dynamically :

    //<summary>
    //Function to Perform a Keyboard KeyPress.
    //</summary>
    void PressKey(Key KeyboardKey)
    {
        KeyEventArgs args = new KeyEventArgs(Keyboard.PrimaryDevice,
        Keyboard.PrimaryDevice.ActiveSource, 0, Key.LeftAlt);
        args.RoutedEvent = Keyboard.KeyDownEvent;
        InputManager.Current.ProcessInput(args);
    }
    

    Code to Append and Remove HotKeyChar :

    //<summary>
    //Function to Append a HotKeyChar to a Content of a Control.
    //</summary>
    void AppendHotKeyChar(ContentControl Ctrl, int KeyIndex)
    {
        if (Ctrl.Content.ToString().Substring(KeyIndex, 1) != "_")
        {
            Ctrl.Content = "_" + Ctrl.Content;
        }
    }
    //<summary>
    //Function to Remove a HotKeyChar to a Content of a Control.
    //</summary>
    void RemoveHotKeyChar(ContentControl Ctrl, int KeyIndex)
    {
        if (Ctrl.Content.ToString().Substring(KeyIndex, 1) == "_")
        {
            Ctrl.Content = Ctrl.Content.ToString().Remove(KeyIndex, 1);
        }
    }
    

    XAML Code for Button Bt1 :

    <Button x:Name="Bt1" Content="Button" HorizontalAlignment="Left" Margin="169,97,0,0" VerticalAlignment="Top" Width="75"/>
    

    Code for Window.Loaded event of the MainWindow (e.g. MainWindow1_Loaded) :

    PressKey(Key.LeftAlt);
    

    Code for Window.KeyDown event of the MainWindow (e.g. MainWindow1_KeyDown) :

    if (e.Key == Key.LeftCtrl)
    {
        AppendHotKey(Bt1, 0);
    }
    

    Code for Window.KeyUp event of the MainWindow (e.g. MainWindow1_KeyUp) :

    if (e.Key == Key.LeftCtrl)
    {
        RemoveHotKey(Bt1, 0);
    }
    

    Now, When you start your app the Alt will be pressed once dynamically.

    And now every-time you press Ctrl, your Control.Content will be Appended with a _ and so the HotKey will appear underlined!
    But one remark is that you should create Control.Content without HotKeyChar '_' but keep an Index of where your _ will be appended.

    But keep in mind that if Alt is pressed again in your app, The code will not work anymore. So, you have to press the Alt again to make the code work!

    Best way to appending and removing a HotKeyChar :

    • Create an instance of List<KeyValuePair<int, Control>> to store the Index of the HotKeyChar and the Control.
    • And now in the KeyDown event just loop through the KeyValuePair<...> in the List<...>..appending the _.
    • In the KeyUp event again just loop through the KeyValuePair<...> in the List<...>..removing the _.

    Hope it Helped!

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

Sidebar

Related Questions

In a WPF label, is aligned like this, that if the font size is
I want to make a WPF Window that behaves like a context menu. So,
I am trying to make a WPF Application containing a treeview, whose data will
Hi iam trying to make an Wpf TextBlock to blink. I want like when
I'd like to make some custom MenuHeaders in WPF so I can have (for
I am trying to make a WPF app (regular Windows app, not XBAP or
I'd like to make my WPF datagrids really pop in my application. Is there
I want to make a WPF control that will perform a custom behavior when
I'm using WPF 3.5 SP1 and I want to achieve something like this (the
I am trying to make my UI more responsive in my WPF app. I

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.