Exemplo n.º 1
0
        private static void UnregisterTextElement(DependencyObject element)
        {
            if (element == null)
            {
                return;
            }

            // Remove overlay text control from adorner.
            OverlayTextAdorner adorner        = (OverlayTextAdorner)element.GetValue(OverlayTextAdornerProperty);
            UIElement          adornedElement = (UIElement)element.GetValue(OverlayTextAdornerHolderProperty);

            if (adornedElement != null && adorner != null)
            {
                adorner.UnlinkOverlayTextControl();

                AdornerLayer adornerLayer = adornedElement.GetAdornerLayer();
                if (adornerLayer != null)
                {
                    adornerLayer.Remove(adorner);
                }
            }

            element.ClearValue(OverlayTextAdornerProperty);
            element.ClearValue(OverlayTextAdornerHolderProperty);

            UnhookTargetElementEventHandlers(element);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private static void OnPasswordChanged(object sender, RoutedEventArgs e)
        {
            PasswordBox passwordBox = sender as PasswordBox;

            if (passwordBox == null)
            {
                return;
            }

            OverlayTextAdorner adorner = (OverlayTextAdorner)passwordBox.GetValue(OverlayTextAdornerProperty);

            if (adorner != null)
            {
                adorner.OnTargetElementTextChanged(passwordBox.Password);
            }
        }
Exemplo n.º 4
0
        private static void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox textBox = sender as TextBox;

            if (textBox == null)
            {
                return;
            }

            OverlayTextAdorner adorner = (OverlayTextAdorner)textBox.GetValue(OverlayTextAdornerProperty);

            if (adorner != null)
            {
                adorner.OnTargetElementTextChanged(textBox.Text);
            }
        }