Esempio n. 1
0
        private static void OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            ListBox listbox = (ListBox)sender;

            // Focus drives the selection when keyboardnavigation is used
            if (!KeyboardNavigation.IsKeyboardMostRecentInputDevice())
            {
                return;
            }

            // Only in case focus moves from one ListBoxItem to another we want the selection to follow focus
            ListBoxItem newListBoxItem = e.NewFocus as ListBoxItem;

            if (newListBoxItem != null && ItemsControlFromItemContainer(newListBoxItem) == listbox)
            {
                DependencyObject oldFocus       = e.OldFocus as DependencyObject;
                Visual           visualOldFocus = oldFocus as Visual;
                if (visualOldFocus == null)
                {
                    ContentElement ce = oldFocus as ContentElement;
                    if (ce != null)
                    {
                        visualOldFocus = KeyboardNavigation.GetParentUIElementFromContentElement(ce);
                    }
                }

                if ((visualOldFocus != null && listbox.IsAncestorOf(visualOldFocus)) ||
                    oldFocus == listbox)
                {
                    listbox.LastActionItem = newListBoxItem;
                    listbox.MakeKeyboardSelection(newListBoxItem);
                }
            }
        }
        // Token: 0x06005134 RID: 20788 RVA: 0x0016C6E8 File Offset: 0x0016A8E8
        private static void OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            ListBox listBox = (ListBox)sender;

            if (!KeyboardNavigation.IsKeyboardMostRecentInputDevice())
            {
                return;
            }
            ListBoxItem listBoxItem = e.NewFocus as ListBoxItem;

            if (listBoxItem != null && ItemsControl.ItemsControlFromItemContainer(listBoxItem) == listBox)
            {
                DependencyObject dependencyObject = e.OldFocus as DependencyObject;
                Visual           visual           = dependencyObject as Visual;
                if (visual == null)
                {
                    ContentElement contentElement = dependencyObject as ContentElement;
                    if (contentElement != null)
                    {
                        visual = KeyboardNavigation.GetParentUIElementFromContentElement(contentElement);
                    }
                }
                if ((visual != null && listBox.IsAncestorOf(visual)) || dependencyObject == listBox)
                {
                    listBox.LastActionItem = listBoxItem;
                    listBox.MakeKeyboardSelection(listBoxItem);
                }
            }
        }