Exemplo n.º 1
0
        IInputElement FindCommonParent(IInputElement control1, IInputElement control2)
        {
            if (control1 == null || control2 == null)
            {
                return(null);
            }
            var seen = new HashSet <IInputElement>(control1.GetSelfAndVisualAncestors().OfType <IInputElement>());

            return(control2.GetSelfAndVisualAncestors().OfType <IInputElement>().FirstOrDefault(seen.Contains));
        }
Exemplo n.º 2
0
        private DragDropEffects RaiseEventAndUpdateCursor(RawDragEventType type, IInputElement root, Point pt, InputModifiers modifiers)
        {
            _lastPosition = pt;

            RawDragEvent rawEvent = new RawDragEvent(_dragDrop, type, root, pt, _draggedData, _allowedEffects);
            var          tl       = root.GetSelfAndVisualAncestors().OfType <TopLevel>().FirstOrDefault();

            tl.PlatformImpl?.Input(rawEvent);

            var effect = GetPreferredEffect(rawEvent.Effects & _allowedEffects, modifiers);

            UpdateCursor(root, effect);
            return(effect);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Focuses a control.
        /// </summary>
        /// <param name="control">The control to focus.</param>
        public void Focus(IInputElement control)
        {
            Contract.Requires <ArgumentNullException>(control != null);

            var current = this.Current as IInteractive;
            var next    = control as IInteractive;
            var scope   = control.GetSelfAndVisualAncestors()
                          .OfType <IFocusScope>()
                          .FirstOrDefault();

            if (scope != null && control != current)
            {
                this.focusScopes[scope] = control;

                if (current != null)
                {
                    current.RaiseEvent(new RoutedEventArgs
                    {
                        RoutedEvent    = InputElement.LostFocusEvent,
                        Source         = current,
                        OriginalSource = current,
                    });
                }

                this.Current = control;

                IKeyboardDevice keyboard = Locator.Current.GetService <IKeyboardDevice>();

                if (keyboard != null)
                {
                    keyboard.FocusedElement = control;
                }

                if (next != null)
                {
                    next.RaiseEvent(new RoutedEventArgs
                    {
                        RoutedEvent    = InputElement.GotFocusEvent,
                        Source         = next,
                        OriginalSource = next,
                    });
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the next control in the specified navigation direction.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="direction">The navigation direction.</param>
        /// <returns>
        /// The next element in the specified direction, or null if <paramref name="element"/>
        /// was the last in the requested direction.
        /// </returns>
        public static IInputElement GetNext(
            IInputElement element,
            NavigationDirection direction)
        {
            Contract.Requires <ArgumentNullException>(element != null);

            var customHandler = element.GetSelfAndVisualAncestors()
                                .OfType <ICustomKeyboardNavigation>()
                                .FirstOrDefault();

            if (customHandler != null)
            {
                var(handled, next) = customHandler.GetNext(element, direction);

                if (handled)
                {
                    if (next != null)
                    {
                        return(next);
                    }
                    else if (direction == NavigationDirection.Next || direction == NavigationDirection.Previous)
                    {
                        return(TabNavigation.GetNextInTabOrder((IInputElement)customHandler, direction, true));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            if (direction == NavigationDirection.Next || direction == NavigationDirection.Previous)
            {
                return(TabNavigation.GetNextInTabOrder(element, direction));
            }
            else
            {
                throw new NotSupportedException();
            }
        }