Exemple #1
0
        protected override void OnActivatingKeyTip(ActivatingKeyTipEventArgs e)
        {
            base.OnActivatingKeyTip(e);

            if (e.OriginalSource != this)
            {
                return;
            }
            var csd = ControlSizeDefinition;

            if (csd == null)
            {
                return;
            }

            if (csd.IsHeaderVisible)
            {
                if (csd.IconSize == RibbonIconSize.Large)
                {
                    e.KeyTipVerticalPlacement = KeyTipVerticalPlacement.KeyTipCenterAtTargetBottom;
                }
                else if (csd.IconSize == RibbonIconSize.Small)
                {
                    e.KeyTipHorizontalPlacement = KeyTipHorizontalPlacement.KeyTipLeftAtTargetCenter;
                    e.PlacementTarget           = Icon as UIElement;
                }
            }
            else
            {
                if (csd.IconSize == RibbonIconSize.Small)
                {
                    e.KeyTipHorizontalPlacement = KeyTipHorizontalPlacement.KeyTipLeftAtTargetCenter;
                }
            }
        }
 protected virtual void OnActivatingKeyTip(ActivatingKeyTipEventArgs e)
 {
     if (e.OriginalSource != this)
     {
         return;
     }
     e.KeyTipVerticalPlacement = KeyTipVerticalPlacement.KeyTipCenterAtTargetBottom;
 }
		protected virtual void OnActivatingKeyTip(ActivatingKeyTipEventArgs e)
		{
			if (e.OriginalSource != this)
				return;
			e.KeyTipVerticalPlacement = KeyTipVerticalPlacement.KeyTipCenterAtTargetBottom;
		}
		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);
			}
		}
Exemple #5
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);
            }
        }