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); }
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); }
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); } }
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); } }