Exemplo n.º 1
0
        /// <summary>
        ///   Invoked when the QuickAccessToolbar's template is applied.
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (_mainPanel != null)
            {
                _mainPanel.Children.Clear();
            }

            if (_overflowPanel != null)
            {
                _overflowPanel.Children.Clear();
            }

            _mainPanel      = GetTemplateChild(MainPanelTemplateName) as RibbonQuickAccessToolBarPanel;
            _overflowPanel  = GetTemplateChild(OverflowPanelTemplateName) as RibbonQuickAccessToolBarOverflowPanel;
            _overflowPopup  = GetTemplateChild(OverflowPopupTemplateName) as Popup;
            _overflowButton = GetTemplateChild(OverflowButtonTemplateName) as RibbonToggleButton;
            if (_overflowButton != null)
            {
                _overflowButton.ToolTipTitle = _overflowButtonToolTipText;
            }

            CoerceValue(DataContextProperty);               // Pick up the Ribbon's DataContext.

            // Set KeyTipAutoGenerationElements property on self.
            IEnumerable <DependencyObject> keyTipAutoGenerationElements = new KeyTipAutoGenerationElements(this);

            KeyTipService.SetKeyTipAutoGenerationElements(this, keyTipAutoGenerationElements);
            if (_overflowPanel != null)
            {
                // Set KeyTipAutoGenerationElements property on overflow panel which helps
                // auto generation of keytips on elements of overflow.
                KeyTipService.SetKeyTipAutoGenerationElements(_overflowPanel, keyTipAutoGenerationElements);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Links the given KeyTipControl as the visual child of self.
        ///     In the process sets various properties of the control.
        /// </summary>
        public void LinkKeyTipControl(DependencyObject keyTipElement, KeyTipControl keyTipControl)
        {
            Debug.Assert(_keyTipControl == null && keyTipControl.KeyTipAdorner == null);
            _keyTipControl = keyTipControl;
            _keyTipControl.KeyTipAdorner = this;
            _keyTipControl.Text          = KeyTipService.GetKeyTip(keyTipElement).ToUpper(KeyTipService.GetCultureForElement(keyTipElement));
            _keyTipControl.IsEnabled     = (bool)keyTipElement.GetValue(UIElement.IsEnabledProperty);
            Style keyTipStyle = KeyTipService.GetKeyTipStyle(keyTipElement);

            _keyTipControl.Style           = keyTipStyle;
            _keyTipControl.RenderTransform = _keyTipTransform;
            bool clearCustomProperties = true;

            if (keyTipStyle == null)
            {
                Ribbon.Ribbon ribbon = RibbonControlService.GetRibbon(PlacementTarget);
                if (ribbon != null)
                {
                    // Use Ribbon properties if the owner element belongs to a Ribbon.
                    keyTipStyle = KeyTipService.GetKeyTipStyle(ribbon);
                    if (keyTipStyle != null)
                    {
                        _keyTipControl.Style = keyTipStyle;
                    }
                    else
                    {
                        clearCustomProperties      = false;
                        _keyTipControl.Background  = ribbon.Background;
                        _keyTipControl.BorderBrush = ribbon.BorderBrush;
                        _keyTipControl.Foreground  = ribbon.Foreground;
                    }
                }
            }
            if (clearCustomProperties)
            {
                _keyTipControl.ClearValue(Control.BackgroundProperty);
                _keyTipControl.ClearValue(Control.BorderBrushProperty);
                _keyTipControl.ClearValue(Control.ForegroundProperty);
            }
            AddVisualChild(_keyTipControl);
            EnsureTransform();
        }