private static void OnEnableWatermarkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.OldValue != null) { var enabled = (bool)e.OldValue; if (enabled) { var textBox = (TextBox)d; var behavior = GetWatermarkTextBoxBehavior(textBox); behavior.Detach(); SetWatermarkTextBoxBehavior(textBox, null); } } if (e.NewValue != null) { var enabled = (bool)e.NewValue; if (enabled) { var textBox = (TextBox)d; var behavior = new WatermarkTextBoxBehavior(textBox); behavior.Attach(); SetWatermarkTextBoxBehavior(textBox, behavior); } } }
private static void SetWatermarkTextBoxBehavior(DependencyObject obj, WatermarkTextBoxBehavior value) { obj.SetValue(WatermarkTextBoxBehaviorProperty, value); }