The Control used inside the KeyTip
Inheritance: System.Windows.Controls.Control
Example #1
0
        /// <summary>
        ///     Notify corresponding KeyTipAdorner regarding size change.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void OnSizeChanged(object sender, SizeChangedEventArgs e)
        {
            KeyTipControl keyTipControl = sender as KeyTipControl;

            if (keyTipControl != null &&
                keyTipControl.KeyTipAdorner != null)
            {
                keyTipControl.KeyTipAdorner.OnKeyTipControlSizeChanged(e);
            }
        }
Example #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();
        }
 /// <summary>
 ///     Unlinks the earlier linked KeyTipControl from visual tree.
 /// </summary>
 public void UnlinkKeyTipControl()
 {
     if (_keyTipControl != null)
     {
         _keyTipControl.KeyTipAdorner = null;
         RemoveVisualChild(_keyTipControl);
         _keyTipControl = null;
     }
 }
 /// <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();
 }
 private static void LinkKeyTipControlToAdorner(KeyTipAdorner adorner, DependencyObject keyTipElement)
 {
     KeyTipService current = Current;
     KeyTipControl keyTipControl = null;
     if (current._cachedKeyTipControls != null &&
         current._cachedKeyTipControls.Count > 0)
     {
         // Retrieve a KeyTipControl from cache for reuse.
         int count = current._cachedKeyTipControls.Count;
         keyTipControl = current._cachedKeyTipControls[count - 1];
         current._cachedKeyTipControls.RemoveAt(count - 1);
     }
     if (keyTipControl == null)
     {
         keyTipControl = new KeyTipControl();
     }
     adorner.LinkKeyTipControl(keyTipElement, keyTipControl);
 }