private static void OnEnableWatermarkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.OldValue != null) { var enabled = (bool)e.OldValue; if (enabled) { var comboBox = (ComboBox)d; var behavior = GetWatermarkComboBoxBehavior(comboBox); behavior.Detach(); SetWatermarkComboBoxBehavior(comboBox, null); } } if (e.NewValue != null) { var enabled = (bool)e.NewValue; if (enabled) { var comboBox = (ComboBox)d; var behavior = new WatermarkComboBoxBehavior(comboBox); behavior.Attach(); SetWatermarkComboBoxBehavior(comboBox, behavior); } } }