Search code examples
wpfcustom-controlsvisibilityadornerrouted-events

WPF - Overriding IsVisible on my custom control


I have a custom control (an Adorner) that wraps another control (a textbox).

public class MyCustomAdorner : Decorator
{
   ...
   public MyCustomAdorner()
   {
      Child = new TextBox();
   }
}

I want to be able to override the VisibilityChanged so that the MyCustomAdorner's event is only fired if the Child's visiblity changes, not the actual decorator. How would I go about this?


Solution

  • On a first approach I would try to bind the Adorner's Visibility to the TextBox's Visibility (not sure if this one works). This way, if the textbox changes visibility, the adorner will follow. If you bind them two way, then it will work the other way around too. So if you don't want it to work both ways, make sure you don't set the Adorner's Visibility.

    If binding the Visibilities together doesn't work, you can try to declare a new property (for example a bool), that manages the visibilities, and bind the two Visibilities to that bool through a Converter. And when you want to change something around the Visibilities, you set this bool to a new value.

    Overriding the VisibilityChange event doesn't sound good to me, also I'm not sure if you can even do that...