Beispiel #1
0
        private static void RegisterTextElement(DependencyObject element)
        {
            if (element == null)
            {
                return;
            }

            UIElement adornedElement = element.GetContainingElement();

            if (adornedElement == null)
            {
                // No parent element
                return;
            }

            AdornerLayer adornerLayer = adornedElement.GetAdornerLayer();

            if (adornerLayer == null)
            {
                // No adorner layer
                return;
            }

            OverlayTextAdorner adorner            = new OverlayTextAdorner(adornedElement);
            OverlayTextControl overlayTextControl = new OverlayTextControl();

            adorner.LinkOverlayTextControl(element, overlayTextControl);
            adornerLayer.Add(adorner);
            element.SetValue(OverlayTextAdornerProperty, adorner);
            element.SetValue(OverlayTextAdornerHolderProperty, adornedElement);

            HookTargetElementEventHandlers(element);
        }
Beispiel #2
0
        /// <summary>
        /// Unlinks current <see cref="OverlayTextControl"/> as the visual child of itself.
        /// </summary>
        public void UnlinkOverlayTextControl()
        {
            if (overlayTextControl == null)
            {
                return;
            }

            overlayTextControl.OverlayTextAdorner = null;
            RemoveVisualChild(overlayTextControl);
            overlayTextControl = null;
        }
Beispiel #3
0
        /// <summary>
        /// Links <see cref="OverlayTextControl"/> as the visual child of itself.
        /// </summary>
        /// <param name="element">
        /// The <see cref="DependencyObject"/> to retrieve the attached properties.
        /// </param>
        /// <param name="targetOverlayTextControl">
        /// The <see cref="OverlayTextControl"/> to link for.
        /// </param>
        public void LinkOverlayTextControl(DependencyObject element, OverlayTextControl targetOverlayTextControl)
        {
            if (overlayTextControl != null || element == null ||
                (targetOverlayTextControl == null || targetOverlayTextControl.OverlayTextAdorner != null))
            {
                return;
            }

            overlayTextControl = targetOverlayTextControl;
            overlayTextControl.OverlayTextAdorner = this;
            overlayTextControl.IsEnabled          = (bool)element.GetValue(UIElement.IsEnabledProperty);
            overlayTextControl.Text  = OverlayTextService.GetText(element);
            overlayTextControl.Style = OverlayTextService.GetOverlayStyle(element);

            AddVisualChild(overlayTextControl);
        }