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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:23:30+00:00 2026-06-03T23:23:30+00:00

I’m having issues with keyboard navigation in my wpf application. Simplified I have a

  • 0

I’m having issues with keyboard navigation in my wpf application.
Simplified I have a horizontal stackpanel with a list of menu items which takes up about a quater of the width of the screen.

Directly under that I have a content control that takes the entire width of the screen.

The content control will change the loaded usercontrol based on the menu item highlighted. All the user controls are setup in the form of

<Grid>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" />
        <Grid Grid.Column="1" />
    </Grid>
</Grid>

The problem is that when I press the down key from the stackpanel it attempts to give focus to the inner grid column directly below it. The first column contains focusable items but the second does not.
This works fine for the first couple of menu items in the stackpanel that are directly above the first column but eventually I get to menu items that are directly over the second column and at this point I am unable to navigate down.

I added the outer grid as shown in the above xaml but this did not help. Why does the focus not move to the first focusable element available in the grid (or inner grid) and how can I force focus into column 1?

I guess I can do this in my viewmodel but I have a significant number of pages all suffering from similar issues so was hoping for an easier solution than having to completely rewrite and control all keyboard navigation.

Any help would be greatly appreciated.

UPDATE: If I set focuasable to true on the first grid the navigation works and ends up in column 1 but obviously the first press of key down “Appears” to do nothing as focus is being given to a grid. I want a similar behaviour but for the navigation to jump the grid straight into column 1.

  • 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-03T23:23:32+00:00Added an answer on June 3, 2026 at 11:23 pm

    No answers to this question so I’ll post my solution. I’m still not happy with it as it seems a bit of a hack but until something better comes along…..
    As mentioned above the keyboard navigation seems to work with a grid around it but I don’t want the grid to have focus.
    What I’ve done is create a custom control that extends grid.
    I override getting keyboard focus then look at the uielement that last had focus and check it is outside the grid (I.E I am navigating into the grid).
    If that is the case then I look at what direction the focus is likely to have come from. I say likely as PredictFocus could come from an up and a left key press for example, which is why I think this solution is a little hacky.
    If a direction is found then I simply move focus once again in that direction. Focusable must be true on the grid for this to work.

    protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            UIElement previousFocus = (UIElement)e.OldFocus;
            if (previousFocus != null)
            {
                if (!previousFocus.IsDescendantOf(this))
                {
                    if (previousFocus.PredictFocus(FocusNavigationDirection.Up).Equals(this))
                    {
                        this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
                    }
                    else if (previousFocus.PredictFocus(FocusNavigationDirection.Down).Equals(this))
                    {
                        this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
                    }
                    else if (previousFocus.PredictFocus(FocusNavigationDirection.Left).Equals(this))
                    {
                        this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
                    }
                    else if (previousFocus.PredictFocus(FocusNavigationDirection.Right).Equals(this))
                    {
                        this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
                    }
                }
            }
            base.OnGotKeyboardFocus(e);
        }        
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.