private void AssociatedObjectLoaded(object sender, System.Windows.RoutedEventArgs e) { this.adorner = new TextBlockAdorner(this.AssociatedObject, this.Label, this.LabelStyle); this.UpdateAdorner(); //AddValueChanged for IsFocused in a weak manner this.notifier = new WeakPropertyChangeNotifier(this.AssociatedObject, UIElement.IsFocusedProperty); this.notifier.ValueChanged += new EventHandler(this.UpdateAdorner); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); VerticalContentAlignment = VerticalAlignment.Center; // Bind the label adorner to the hint text-box. _hintTextBoxAdornerLayer = AdornerLayer.GetAdornerLayer(this); _hintTextBlockAdorner = new TextBlockAdorner(this, HintText, HintTextStyle); UpdateAdorner(); // Attach the text-change event handler. var hasTextPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(HasTextProperty, typeof(HintTextBox)); hasTextPropertyDescriptor?.AddValueChanged(this, (sender, args) => UpdateAdorner()); }
private void AssociatedObjectLoaded(object sender, RoutedEventArgs e) { this.adorner = new TextBlockAdorner(this.AssociatedObject, this.LabelStyle); // Set binding in code so that it updates everytime Binding binding = new Binding(); binding.Source = this; binding.Path = new PropertyPath("Label"); adorner.adornerTextBlock.SetBinding(TextBlock.TextProperty, binding); this.UpdateAdorner(); //AddValueChanged for IsFocused in a weak manner this.notifier = new WeakPropertyChangeNotifier(this.AssociatedObject, UIElement.IsFocusedProperty); this.notifier.ValueChanged += this.UpdateAdorner; }