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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:57:06+00:00 2026-06-13T05:57:06+00:00

I have an app that has a main window that contains a bunch of

  • 0

I have an app that has a main window that contains a bunch of stuff. From time to time the user will do something in response to which I want to display something else entirely in the main window, temporarily hiding what is there.

I’m doing this by making the outermost element in the main window a Grid with no rows or columns defined. Every element in the grid, then will completely fill the one single cell in the grid, drawing on top of the others.

My regular bunch stuff, then, is in the first element of the grid, and my temporary something else is a UserControl as the second element of the grid, that is normally set Visibility=Collapsed.

Except for the KeyBinding everything works fine. When the appropriate command is triggered in the regular bunch of stuff, the visibility on the UserControl is set to Visible, and it covers the regular bunch of stuff completely. When the user clicks on the close button on the UserControl, it’s visibility is set to Collapsed, again, and it disappears and the regular bunch of stuff is revealed.

My problem is with KeyBindings. I have a few defined on the UserControl – that should not be defined on the main window – and they don’t work. Or rather, they work fine once I click inside the UserControl, but they don’t work until I do.

I need them to work as soon as the UserControl is made visible, without requiring the user to click or tab into the UserControl proper.

My guess is that this has something to do with keyboard focus – but I’ve been unable to find a way to set the focus on the UserControl. Here’s the thing – the only element within the UserControl is a tab control, all of the tabs of which are dynamically constructed via templates. There are no elements known at compile time that I can reference explicitly and pass to KeyBoard.Focus().

So, am I right in thinking that it’s lack of focus that is causing the problem? And if so, how can I set focus to an element in a TabControl, when I don’t even know how many tabs there are, let alone which is the selected one?

  • 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-13T05:57:08+00:00Added an answer on June 13, 2026 at 5:57 am

    I wanted this control to have the focus, when it became visible. So in the constructor, I set up a handler on IsVisibleChanged.

    public MyControl
    {
        ...
        this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(MyControl_IsVisibileChanged);
    }
    
    void MyControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        if (!(bool)e.NewValue)
            return;
    
        this.Focusable = true;
        Keyboard.Focus(this);
    }
    

    I could have set Focusable in the XAML, but I prefer it in the code-behind, so that all of the relevant code is in one place.

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

Sidebar

Related Questions

I have an app that has a mapview, and it shows 20 pins (from
I have an app that has a bunch of Core Data that it needs
I have a NIB which contains two windows, one is the app's main window
Have an app that has listings - think classified ads - and each listing
I have an app that has different names for different languages. How do I
I have an app that has a centre view with two views off to
I have an app that has a tabbar at the bottom. When I select
I have an app that has a TableView, NavigationView and TabBar running together. There
I have an app that has a list of items. My customer prefers to
i have an app that has a few checkboxes in the settings and then

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.