Esempio n. 1
0
 private static void ContentTemplateProperty_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is TextBoxBase textBox && Watermarking.GetAdorner(textBox) is WatermarkAdorner adorner)
     {
         adorner.ContentTemplate = (DataTemplate?)e.NewValue;
     }
 }
Esempio n. 2
0
        private static void TextBox_Loaded(object sender, RoutedEventArgs e)
        {
            TextBoxBase textBox = (TextBoxBase)sender;

            textBox.Loaded -= Watermarking.TextBox_Loaded;
            if (Watermarking.GetContent(textBox) is object content)
            {
                Watermarking.SetAdorner(textBox, new WatermarkAdorner(textBox, content, Watermarking.GetContentTemplate(textBox)));
            }
        }
Esempio n. 3
0
 private static void ContentProperty_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (!(d is TextBoxBase textBox))
     {
         return;
     }
     if (textBox.IsLoaded)
     {
         Watermarking.SetAdorner(textBox, e.NewValue == null ? default : new WatermarkAdorner(textBox, e.NewValue, Watermarking.GetContentTemplate(textBox)));
     }
     else if (e.NewValue != null && e.OldValue == null)
     {
         textBox.Loaded += Watermarking.TextBox_Loaded;
     }
     else if (e.NewValue == null && e.OldValue != null)
     {
         textBox.Loaded -= Watermarking.TextBox_Loaded;
     }
 }