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 371023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:04:29+00:00 2026-05-12T14:04:29+00:00

In WPF, you can assign a label a mnemonic, and tell it which control

  • 0

In WPF, you can assign a label a mnemonic, and tell it which control to activate with the “Target” property.

This doesn’t work if the target is a WindowsFormsHost. Is there a known solution to this?

Here’s an example. I am trying to make ALT-S activate the masked text box.

<Label 
   Width="Auto" 
   Target="{Binding ElementName=tbStartTime}" 
   TabIndex="12">
   _Start Time:
</Label>
<WindowsFormsHost 
    Name="tbStartTime" 
    TabIndex="13">
 <wf:MaskedTextBox Name="wfStartTime"  Mask="90:00" />
/WindowsFormsHost>
  • 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-12T14:04:29+00:00Added an answer on May 12, 2026 at 2:04 pm

    I don’t think it’s possible, at least not without some extra boilerplate code… WPF and Windows Forms have a completely different model, and the Target property isn’t designed to refer to WinForms controls.

    Instead, I think you should use a WPF implementation of MaskedTextBox, like this one (you can find many other examples with Google). Using WinForms controls in a WPF app is rarely a good idea if you can avoid it…

    EDIT: I just checked the doc : it is definitely not possible to do what you want, because the type of the Label.Target property is UIElement, and WinForms controls are clearly not UIElements…


    UPDATE: OK, I misread your code… you’re referencing the WindowsFormsHost, which is a UIElement. Whoever voted me up was wrong too 😉

    I think the problem is that the WindowsFormsHost takes the focus when you press Alt-S, not the MaskedTextBox. Here’s a quick workaround :

    XAML :

    <WindowsFormsHost 
        Name="tbStartTime" 
        TabIndex="13"
        GotFocus="tbStartTime_GotFocus">
     <wf:MaskedTextBox Name="wfStartTime"  Mask="90:00" />
    </WindowsFormsHost>
    

    Code-behind :

        private void tbStartTime_GotFocus(object sender, RoutedEventArgs e)
        {
            tbStartTime.Child.Focus();
        }
    

    Anyway, my previous advice is still relevant : you’d better use a WPF MaskedTextBox…

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

Sidebar

Related Questions

In a WPF app, is there a object I can assign to FileSystemWatcher.SynchronizingObject? I
I know how to create a custom user control in WPF but how can
How can I add a scrollbar to the wrappanel control in WPF. Some of
Is there any way in WPF I can getb a value from a property
In WPF: Can someone please explain the relationship between DependencyProperty and Databinding? I have
Can both WPF and Windows forms controls be used within one application? How difficult
I'd like to make some custom MenuHeaders in WPF so I can have (for
How can I constrain a vertical WPF StackPanel 's width to the most narrow
How can I go about hosting flash content inside a WPF form and still
Can I host an XBAP in my WPF application dynamically? Can I download an

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.