Ejemplo n.º 1
0
        private void OnKeyTipExactMatch(DependencyObject exactMatchElement)
        {
            if (!((bool)(exactMatchElement.GetValue(UIElement.IsEnabledProperty))))
            {
                Menu.MenuRibbon.Beep();
                _prefixText = string.Empty;
                return;
            }

            HideCurrentShowingKeyTips();
            _prefixText = string.Empty;

            // KeyTips might have been dismissed by one of the event handlers
            // hence check again.
            if (State == KeyTipState.None)
            {
                return;
            }

            var oldFocus = Keyboard.FocusedElement;

            var args = new KeyTipAccessedEventArgs();

            args.RoutedEvent = PreviewKeyTipAccessedEvent;
            IInputElement inputElement = exactMatchElement as IInputElement;

            if (inputElement != null)
            {
                inputElement.RaiseEvent(args);
                args.RoutedEvent = KeyTipAccessedEvent;
                inputElement.RaiseEvent(args);
            }

            object           newFocus = Keyboard.FocusedElement;
            DependencyObject newScope = args.TargetKeyTipScope;

            if (newScope != null && !KeyTipService.GetIsKeyTipScope(newScope) && newScope != globalScope)
            {
                throw new InvalidOperationException();
            }

            if (newScope == null && KeyTipService.GetIsKeyTipScope(exactMatchElement))
            {
                newScope = exactMatchElement;
            }

            if (newScope != null)
            {
                // Show KeyTips for new scope in a dispatcher operation.
                Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => PushKeyTipsScope(newScope, true)), DispatcherPriority.Loaded);
            }
            else
            {
                LeaveKeyTipMode(oldFocus == newFocus /*restoreFocus*/);
            }
        }
Ejemplo n.º 2
0
        protected virtual void OnKeyTipAccessed(KeyTipAccessedEventArgs e)
        {
            if (e.OriginalSource != this)
            {
                return;
            }

            OnClick();
            e.Handled = true;

            if (IsOpen && KeyTipService.GetIsKeyTipScope(this))
            {
                e.TargetKeyTipScope = this;
            }
        }