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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:40:57+00:00 2026-06-07T17:40:57+00:00

I want to allow users to navigate within a control using the Arrow Keys.

  • 0

I want to allow users to navigate within a control using the Arrow Keys.

Users should still be able to navigate horizontally with the Tab and Shift + Tab controls but I want them to be able to navigate vertically (which may skip controls that would be focused if they navigated horizontally).

If I use the MoveFocus method on UIElement what seems to happen is that certain controls are skipped such as buttons and editable combo-boxes.

Does anyone know why this is? These controls are focused normally using TAB but FocusDirections of Up/Down/Next seem to skip the controls. If I take a look at PredictFocus it seems to report that Buttons should be focusable in this way but not editable combo-boxes.

Demo code below:
XAML:

<Window x:Class="Focus.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        Width="525"
        Height="350">
    <Window.Resources>
        <Style x:Key="FocusStyle">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle Stroke="CadetBlue" StrokeThickness="2" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="txtBox1" Width="75"/>
                <TextBox Width="200"
                         Name="txtBox1"
                         Margin="5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         FocusVisualStyle="{StaticResource FocusStyle}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="button1" Width="75" />
                <Button Width="200"
                        Name="button1"
                        Height="25"
                        Margin="5"
                        Content="Hello"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        FocusVisualStyle="{StaticResource FocusStyle}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="txtBox2" Width="75"/>
                <TextBox Width="200"
                         Name="text2"
                         Margin="5"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         FocusVisualStyle="{StaticResource FocusStyle}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="comboBox" Width="75"/>
                <ComboBox Width="200"
                         Margin="5"
                         Name="comboBox"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         FocusVisualStyle="{StaticResource FocusStyle}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="txtBox4" Width="75"/>
                <TextBox Width="200"
                         Margin="5"
                         Name="txtBox4"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         FocusVisualStyle="{StaticResource FocusStyle}" />
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label Content="comboBox2" Width="75"/>
                <ComboBox Width="200"
                         Margin="5"
                          IsEditable="True"
                         Name="comboBox2"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         FocusVisualStyle="{StaticResource FocusStyle}" />
            </StackPanel>
            <TextBlock Margin="3" Text="{Binding FocussedControl.Name, StringFormat=Focused Control: {0}}" />
            <TextBlock Margin="3" Text="{Binding PredictedFocusControl.Name, StringFormat=Predicted Focus {0}}"/>
        </StackPanel>
    </Grid>
</Window>

MainWindow.Xaml.cs :

using System.Windows;
using System.Windows.Input;

namespace Focus
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }

        public IInputElement FocussedControl
        {
            get { return (IInputElement)GetValue(FocussedControlProperty); }
            set { SetValue(FocussedControlProperty, value); }
        }

        public static readonly DependencyProperty FocussedControlProperty =
            DependencyProperty.Register("FocussedControl", typeof(IInputElement), typeof(MainWindow));

        public DependencyObject PredictedFocusControl
        {
            get { return (DependencyObject)GetValue(PredictedFocusControlProperty); }
            set { SetValue(PredictedFocusControlProperty, value); }
        }

        public static readonly DependencyProperty PredictedFocusControlProperty =
            DependencyProperty.Register("PredictedFocusControl", typeof(DependencyObject), typeof(MainWindow));

        protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            FocussedControl = e.NewFocus;
        }

        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            base.OnPreviewKeyDown(e);
            if (e.Key == Key.Down)
            {
                var success = (FocussedControl as UIElement).MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
                System.Diagnostics.Debug.Assert(success);
                PredictedFocusControl = (FocussedControl as UIElement).PredictFocus(FocusNavigationDirection.Down);
            }
            else if (e.Key == Key.Up)
            {
                var success = (FocussedControl as UIElement).MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
                PredictedFocusControl = (FocussedControl as UIElement).PredictFocus(FocusNavigationDirection.Up);
            }
        }
    }
}
  • 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-07T17:40:59+00:00Added an answer on June 7, 2026 at 5:40 pm

    I fixed it by setting IsTabStop=true in the ComboBox even though Tab was working to focus on the control:

    <Window x:Class="Focus.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow"
            Width="525"
            Height="350">
        <Window.Resources>
            <Style x:Key="FocusStyle">
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Rectangle Stroke="CadetBlue" StrokeThickness="2" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <Grid>
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Width="75" Content="txtBox1" />
                    <TextBox Name="txtBox1"
                             Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                    <TextBox Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Width="75" Content="button1" />
                    <Button Name="button1"
                            Width="200"
                            Height="25"
                            Margin="5"
                            HorizontalAlignment="Left"
                            FocusVisualStyle="{StaticResource FocusStyle}"
                            VerticalAlignment="Top"
                            Content="Hello" />
                    <TextBox Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Width="75" Content="txtBox2" />
                    <TextBox Name="text2"
                             Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             FocusVisualStyle="{StaticResource FocusStyle}"
                             VerticalAlignment="Top" />
                    <TextBox Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Width="75" Content="comboBox" />
                    <ComboBox Name="comboBox"
                              Width="200"
                              Margin="5"
                              HorizontalAlignment="Left"
                              VerticalAlignment="Top"
                              FocusVisualStyle="{StaticResource FocusStyle}">
                        <ComboBoxItem Content="Item1" />
                        <ComboBoxItem Content="Item2" />
                        <ComboBoxItem Content="Item3" />
                        <ComboBoxItem Content="Item4" />
                    </ComboBox>
                    <TextBox Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <Label Width="75" Content="txtBox4" />
                    <TextBox Name="txtBox4"
                             Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                    <TextBox Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal"  >
                    <Label Width="75" Content="comboBox2" />
                    <ComboBox Name="comboBox2"
                              Width="200"
                              Margin="5"
                              HorizontalAlignment="Left"
                              VerticalAlignment="Top"
                              IsTabStop="True"
                              FocusVisualStyle="{StaticResource FocusStyle}"
                              IsEditable="True" />
                    <TextBox Width="200"
                             Margin="5"
                             HorizontalAlignment="Left"
                             VerticalAlignment="Top"
                             FocusVisualStyle="{StaticResource FocusStyle}" />
                </StackPanel>
                <TextBlock Margin="3" Text="{Binding FocussedControl.Name, StringFormat=Focused Control: {0}}" />
                <TextBlock Margin="3" Text="{Binding PredictedFocusControl.Name, StringFormat=Predicted Focus {0}}" />
            </StackPanel>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to allow users of my application to add sub-users and set privileges
I want to allow users to put in am img url instead of uploading
I want to allow users to either have there username field empty at any
I want to allow users to make their own Python mods for my game,
I want to allow users to select a local directory on a webpage (and
I have some labels that I want to allow users to edit. Is it
I am making an application in Java and I want to allow users to
I'm building a simple web based forum application. I want to allow users to
I have created Twitter bots for many geographic locations. I want to allow users
I'm currently developing an URL shortening service. I want to allow users to see

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.