GetRibbon() 공개 정적인 메소드

Gets the value of the Ribbon property.
public static GetRibbon ( DependencyObject element ) : Ribbon
element System.Windows.DependencyObject
리턴 Ribbon
예제 #1
0
        private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonContextMenu contextMenu = (RibbonContextMenu)d;

            if (!(bool)(e.NewValue))
            {
                if (!contextMenu._ignoreDismissPopupsOnNextClose)
                {
                    UIElement dismissPopupSource = contextMenu.GetDismissPopupSource();
                    if (CanRaiseDismissPopups(dismissPopupSource))
                    {
                        // Raise DismissPopup on owner if can raise and if
                        // was not asked to ignore.
                        dismissPopupSource.RaiseEvent(new RibbonDismissPopupEventArgs(RibbonDismissPopupMode.Always));
                        ((Ribbon)(RibbonControlService.GetRibbon(dismissPopupSource))).RestoreFocusOnContextMenuClose();
                    }
                }
                else
                {
                    contextMenu.RestoreFocusToRibbon();
                    contextMenu._ignoreDismissPopupsOnNextClose = false;
                }
            }
            else
            {
                contextMenu._ignoreDismissPopupsOnNextClose = false;
            }
        }
예제 #2
0
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                DependencyObject d = value as DependencyObject;

                if (d != null)
                {
                    Ribbon ribbon = RibbonControlService.GetRibbon(d);
                    if (ribbon != null &&
                        !ribbon.ShowQuickAccessToolBarOnTop)
                    {
                        if (_mode == ConverterMode.Header)
                        {
                            return(ShowQATAboveText);
                        }
                        else
                        {
                            return(RibbonCommands.ShowQuickAccessToolBarAboveRibbonCommand);
                        }
                    }
                }

                if (_mode == ConverterMode.Header)
                {
                    return(ShowQATBelowText);
                }
                else
                {
                    return(RibbonCommands.ShowQuickAccessToolBarBelowRibbonCommand);
                }
            }
예제 #3
0
        /// <summary>
        ///     Tries to restore focus to the first focusable element across
        ///     the ancestor chain of ContextMenuOriginalSource. Should
        ///     be called only when Ribbon is supposed to retain the focus.
        /// </summary>
        private void RestoreFocusToRibbon()
        {
            DependencyObject current = GetDismissPopupSource();

            if (current == null)
            {
                return;
            }
            Ribbon ribbon = RibbonControlService.GetRibbon(current);

            if (ribbon == null)
            {
                return;
            }
            while (current != null)
            {
                UIElement uie = current as UIElement;
                if (uie != null && uie.Focusable)
                {
                    uie.Dispatcher.BeginInvoke(
                        (Action) delegate()
                    {
                        if (!ribbon.IsKeyboardFocusWithin)
                        {
                            uie.Focus();
                        }
                    },
                        DispatcherPriority.Input,
                        null);
                    break;
                }
                current = TreeHelper.GetParent(current);
            }
        }
예제 #4
0
        /// <summary>
        ///     Property changed callback for tooltip PlacementTarget property.
        /// </summary>
        private static void OnPlacementTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonToolTip ribbonToolTip = (RibbonToolTip)d;
            UIElement     target        = e.NewValue as UIElement;

            if (target == null)
            {
                ribbonToolTip.Ribbon = null;
            }
            else
            {
                ribbonToolTip.Ribbon = RibbonControlService.GetRibbon(target);
            }
        }
 private void TransferPseudoInheritedProperties()
 {
     if (_templateRoot != null)
     {
         // Ribbon is an inherited property. In non-MVVM scenarios where
         // controls are directly added under RibbonGroup in XAML, RibbonGroup
         // is the logical parent of those controls and they get the value
         // of RibbonParent set from their logical parent. When a RibbonGroup
         // get collapsed and its template changes, due to a bug in framework
         // the inheritance value of those controls is lost during visual tree
         // change and never again gets updated. The workaround is to set the
         // local value on those controls from RibbonContentPresenter which
         // would be their visual parent. This works because Ribbon property is
         // readonly.
         RibbonControlService.SetRibbon(_templateRoot, RibbonControlService.GetRibbon(this));
         RibbonHelper.TransferPseudoInheritedProperties(this, _templateRoot);
     }
 }
예제 #6
0
        private static bool CanRaiseDismissPopups(UIElement dismissPopupSource)
        {
            // Contextmenu raises DismissPopup event on the source only
            // if it is in a popup and is in a Ribbon.
            if (dismissPopupSource == null ||
                RibbonControlService.GetRibbon(dismissPopupSource) == null)
            {
                return(false);
            }

            Popup ancestorPopup = TreeHelper.FindAncestor(dismissPopupSource, delegate(DependencyObject element) { return(element is Popup); }) as Popup;

            if (ancestorPopup == null ||
                !ancestorPopup.IsOpen)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        ///     Helper method which scrolls item at given index into view.
        ///     Can be used as a dispatcher operation.
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private object ScrollContainerIntoView(object arg)
        {
            int index = (int)arg;
            FrameworkElement element = ItemContainerGenerator.ContainerFromIndex(index) as FrameworkElement;

            if (element != null)
            {
                element.BringIntoView();

                // If there is a margin on TabHeader on the end, BringIntoView call
                // may not scroll to the end. Explicitly scroll to end in such cases.
                IScrollInfo scrollInfo = InternalItemsHost as IScrollInfo;
                if (scrollInfo != null)
                {
                    ScrollViewer scrollViewer = scrollInfo.ScrollOwner;
                    if (scrollViewer != null)
                    {
                        Ribbon ribbon = RibbonControlService.GetRibbon(this);
                        if (ribbon != null)
                        {
                            int displayIndex = ribbon.GetTabDisplayIndexForIndex(index);
                            if (displayIndex == 0)
                            {
                                // If this tab header is the first tab header displayed
                                // then scroll to the left end.
                                scrollViewer.ScrollToLeftEnd();
                            }
                            else if (ribbon.GetTabIndexForDisplayIndex(displayIndex + 1) < 0)
                            {
                                // If this tab header is the last tab header displayed
                                // then scroll to the right end.
                                scrollViewer.ScrollToRightEnd();
                            }
                        }
                    }
                }
            }
            return(null);
        }
예제 #8
0
        private UIElement GetDismissPopupSource()
        {
            UIElement placementTarget = PlacementTarget;

            if (placementTarget == null)
            {
                return(null);
            }
            Ribbon ribbon = RibbonControlService.GetRibbon(placementTarget);

            if (ribbon == null)
            {
                return(null);
            }
            // The original source for corresponding ContextMenuOpening will
            // be the original source for DismissPopup event.
            UIElement returnValue = ribbon.ContextMenuOriginalSource;

            if (returnValue == null)
            {
                returnValue = placementTarget;
            }
            return(returnValue);
        }