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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:19:32+00:00 2026-05-16T00:19:32+00:00

I have created a TreeViewComboBox control, in this I am having a ComboBox with

  • 0

I have created a TreeViewComboBox control, in this I am having a ComboBox with items as TreeView, but Keyboard Navigation doesn’t work on the TreeView. I am not able to navigate through the TreeViewItems using keyboard. Any help plz?

  • 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-16T00:19:33+00:00Added an answer on May 16, 2026 at 12:19 am

    I has a similar issue when implementing our property grid control. The issue in our specific, which could be similar to yours, was that the keyboard focus events were not routing to the TreeViewItem.

    The way we solved it was by adding an AttachedProperty to the TreeViewItem style and selecting the node when it gets keyboard focus. I implemented this using a Service pattern. See below:

    In XAML:

    <Style x:Key="EditorBorder" TargetType="{x:Type Border}">
        <Setter Property="Controls_Services:TreeViewItemService.SelectWhenKeyboardIsFocused" Value="True"/>
    </Style>
    

    In Codebehind:

      public class TreeViewItemService
      {
        public static readonly DependencyProperty SelectWhenKeyboardIsFocusedProperty = DependencyProperty.RegisterAttached("SelectWhenKeyboardIsFocused",
          typeof(bool), typeof(TreeViewItemService), new FrameworkPropertyMetadata(false, TreeViewItemService.OnSelectWhenKeyboardIsFocusedPropertyChanged));
    
        static void OnSelectWhenKeyboardIsFocusedPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
          FrameworkElement element = sender as FrameworkElement;
          if (element == null)
            return;
    
          TreeViewItem target = MTVisualTreeHelper.FindParent<TreeViewItem>(element as DependencyObject);
          if (target != null)
            new IsSelectedOnKeyboardFocusAction(element, target);
        }
    
        public static bool GetSelectWhenKeyboardIsFocused(FrameworkElement target)
        {
          return (bool)target.GetValue(SelectWhenKeyboardIsFocusedProperty);
        }
    
        public static void SetSelectWhenKeyboardIsFocused(FrameworkElement target, bool value)
        {
          target.SetValue(SelectWhenKeyboardIsFocusedProperty, value);
        }
    
        private class IsSelectedOnKeyboardFocusAction
        {
          TreeViewItem m_Target;
          FrameworkElement m_Source;
    
          public IsSelectedOnKeyboardFocusAction(FrameworkElement source, TreeViewItem item)
          {
            m_Source = source;
            m_Target = item;
            m_Source.Loaded += OnSource_Loaded;
            m_Source.Unloaded += OnSource_Unloaded;
          }
    
          void OnSource_Loaded(object sender, RoutedEventArgs e)
          {
            m_Source.PreviewMouseLeftButtonDown += OnSource_PreviewMouseLeftButtonDown;
            m_Source.GotFocus += OnSource_GotFocus;
            m_Source.LostFocus += OnSource_LostFocus;
            m_Source.GotKeyboardFocus += OnSource_GotKeyboardFocus;
            m_Source.LostKeyboardFocus += OnSource_LostKeyboardFocus;
          }
    
          void OnSource_Unloaded(object sender, RoutedEventArgs e)
          {
            m_Source.PreviewMouseLeftButtonDown -= OnSource_PreviewMouseLeftButtonDown;
            m_Source.GotFocus -= OnSource_GotFocus;
            m_Source.LostFocus -= OnSource_LostFocus;
            m_Source.GotKeyboardFocus -= OnSource_GotKeyboardFocus;
            m_Source.LostKeyboardFocus -= OnSource_LostKeyboardFocus;
          }
    
          void OnSource_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
          {
            if (!m_Target.IsSelected)
              m_Target.IsSelected = true;
          }
    
          void OnSource_GotFocus(object sender, RoutedEventArgs e)
          {
            if (!m_Target.IsSelected)
              m_Target.IsSelected = true;
          }
    
          void OnSource_LostFocus(object sender, RoutedEventArgs e)
          {
            if (m_Target.IsSelected)
              m_Target.IsSelected = false;
          }
    
          void OnSource_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
          {
            if (!m_Target.IsSelected)
              m_Target.IsSelected = true;
          }
    
          void OnSource_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
          {
            if (m_Target.IsSelected)
              m_Target.IsSelected = false;
          }
    
        }
    
      }
    

    HTH,

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

Sidebar

Related Questions

No related questions found

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.