private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var adornedElement = (Control)d; if (Equals(e.NewValue, true)) { var adorner = adornedElement.GetAdorner(); if (adorner == null) { adorner = new WatermarkAdorner(adornedElement); adornedElement.SetAdorner(adorner); var textStyle = adornedElement.GetTextStyle(); if (textStyle != null) { adorner.SetCurrentValue(WatermarkAdorner.TextStyleProperty, textStyle); } AdornerService.Show(adorner); adornedElement.SetCurrentValue(AdornerProperty, adorner); } else { Debug.Assert(condition: false, message: "Already visible"); } } else { var adorner = adornedElement.GetAdorner(); if (adorner != null) { AdornerService.Remove(adorner); adornedElement.ClearValue(AdornerProperty); } } }
private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { //Debug.Print($"Visible changed to: {e.NewValue}"); var textBox = (TextBox)d; if (Equals(e.NewValue, true)) { var adorner = textBox.GetAdorner(); if (adorner == null) { adorner = new WatermarkAdorner(textBox); textBox.SetAdorner(adorner); var textStyle = textBox.GetTextStyle(); if (textStyle != null) { adorner.SetCurrentValue(WatermarkAdorner.TextStyleProperty, textStyle); } AdornerService.Show(adorner); textBox.SetValue(AdornerProperty, adorner); } else { Debug.Assert(false, "Already visible"); } } else { var adorner = textBox.GetAdorner(); if (adorner != null) { AdornerService.Remove(adorner); textBox.ClearValue(AdornerProperty); } } }
private static void SetAdorner(this DependencyObject element, WatermarkAdorner value) { element.SetValue(AdornerProperty, value); }