Example #1
0
        private bool AllowHandleKeyEvent(FocusNavigationDirection direction)
        {
            if (!IsSelected)
            {
                return(false);
            }

            DependencyObject currentFocus = Keyboard.FocusedElement as DependencyObject;

            if (currentFocus != null && UIElementHelper.IsUIElementOrUIElement3D(currentFocus))
            {
                DependencyObject predict = UIElementHelper.PredictFocus(currentFocus, direction);
                if (predict != currentFocus)
                {
                    while (predict != null)
                    {
                        TreeViewItem item = predict as TreeViewItem;
                        if (item == this)
                        {
                            return(false); // There is a focusable item in the header
                        }
                        else if ((item != null) || (predict is TreeView))
                        {
                            return(true);
                        }

                        predict = VisualTreeHelper.GetParent(predict);
                    }
                }
            }

            return(true);
        }