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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:50:17+00:00 2026-05-23T06:50:17+00:00

I have a reusable usercontrol that uses a few commands and corresponding keyboard gestures,

  • 0

I have a reusable usercontrol that uses a few commands and corresponding keyboard gestures,
(specifically Escape and Ctrl+1…Ctrl+9)

Now as I use this usercontrol in multiple locations I’d like to define the input gestures in the usercontrol, which works fine as long as the focus is within the usercontrol. However, I’d need it to work as long as focus is within the current page/window.

How can I do it, or do I really have to do command/input bindings on every page?

  • 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-23T06:50:18+00:00Added an answer on May 23, 2026 at 6:50 am

    You could handle the Loaded event of the UserControl and walk up the logical tree to find the owning page/window, then you can add the bindings there.

    e.g.

    public partial class Bogus : UserControl
    {
        public Bogus()
        {
            Loaded += (s, e) => { HookIntoWindow(); };
            InitializeComponent();
        }
    
        private void HookIntoWindow()
        {
            var current = this.Parent;
            while (!(current is Window) && current is FrameworkElement)
            {
                current = ((FrameworkElement)current).Parent;
            }
            if (current != null)
            {
                var window = current as Window;
                // Add input bindings
                var command = new AlertCommand();
                window.InputBindings.Add(new InputBinding(command, new KeyGesture(Key.D1, ModifierKeys.Control)));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Q1 If I have a reusable library that is available, that uses interfaces with
I'd like to have a reusable validator that I can use on a group
I have a few apps in my project that I want to be reusable.
I have a reusable HTML fragment that I use to list items. So to
let us assume that I have a reusable business layer that further makes use
I have a few apps that I am trying to develop a reusable URL
Have a matrix report now that has Position, Hours and Wages for a location
I'd like to have a reusable logging method or function that spits out the
I am writing an application using Symfony. I have some reusable components that I
I have a winforms app that uses a strongly typed custom DataSet for holding

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.