Esempio n. 1
0
        private static void OnIsKeyTipScopeChanged(DependencyObject scopeElement, DependencyPropertyChangedEventArgs e)
        {
            KeyTipService current = Current;

            Current.scopeToElementMap.UpdateScope(scopeElement);
        }
Esempio n. 2
0
        private static void OnShowingKeyTipChanged(DependencyObject element, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                var uie = (UIElement)element.LogicalHierarchy().FirstOrDefault(x => x is UIElement);
                if (uie != null && uie.Visibility != Visibility.Visible)
                {
                    element.ClearValue(ShowingKeyTipProperty);
                    return;
                }

                // Raise the ActivatingKeyTip event.
                var activatingEventArgs = new ActivatingKeyTipEventArgs();
                var inputElement        = element as IInputElement;
                if (inputElement != null)
                {
                    inputElement.RaiseEvent(activatingEventArgs);
                }

                // KeyTips could have been dismissed due to one
                // of the event handler, hence check again.
                KeyTipService current = Current;
                if (current.State == KeyTipState.None)
                {
                    element.ClearValue(ShowingKeyTipProperty);
                    return;
                }

                if (activatingEventArgs.KeyTipVisibility != Visibility.Visible)
                {
                    element.ClearValue(ShowingKeyTipProperty);
                    return;
                }

                // Create the KeyTip and add it as the adorner.
                AdornerLayer adornerLayer   = null;
                var          adornedElement = (UIElement)(activatingEventArgs.PlacementTarget ?? element).VisualHierarchy().FirstOrDefault(x => x is UIElement);
                if (adornedElement != null)
                {
                    adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
                    if (adornerLayer == null || !adornedElement.IsVisible)
                    {
                        element.ClearValue(ShowingKeyTipProperty);
                        return;
                    }
                }

                KeyTipAdorner adorner = new KeyTipAdorner(adornedElement,
                                                          activatingEventArgs.PlacementTarget,
                                                          activatingEventArgs.KeyTipHorizontalPlacement,
                                                          activatingEventArgs.KeyTipVerticalPlacement,
                                                          activatingEventArgs.KeyTipHorizontalOffset,
                                                          activatingEventArgs.KeyTipVerticalOffset,
                                                          activatingEventArgs.Handled ? null : activatingEventArgs.OwnerRibbonGroup);
                adorner.KeyTipControl = current.mKeyTipControlRecycler.Get();
                adorner.Element       = element;
                adornerLayer.Add(adorner);
                element.SetValue(KeyTipAdornerProperty, adorner);
                element.SetValue(KeyTipAdornerHolderProperty, adornedElement);

                if (adorner.VisualHierarchy().FirstOrDefault(x => x is ScrollViewer) == null)
                {
                    current.EnqueueAdornerLayerForPlacementProcessing(adornerLayer);
                }

                // add the element to currentActiveKeyTipElement list.
                current._currentActiveKeyTipElements.Add(element);
            }
            else
            {
                // Remove keytip from adorner.
                KeyTipAdorner adorner = (KeyTipAdorner)element.GetValue(KeyTipAdornerProperty);
                if (adorner != null)
                {
                    Current.mKeyTipControlRecycler.Recycle(adorner.KeyTipControl);
                    adorner.KeyTipControl = null;
                }

                UIElement adornedElement = (UIElement)element.GetValue(KeyTipAdornerHolderProperty);
                if (adornedElement != null && adorner != null)
                {
                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
                    if (adornerLayer != null)
                    {
                        adornerLayer.Remove(adorner);
                    }
                }
                element.ClearValue(KeyTipAdornerProperty);
                element.ClearValue(KeyTipAdornerHolderProperty);
            }
        }