I want to set up an event to run when the Visibility is changed on a WPF Canvas control.
canvas1.VisibleChanged += new EventHandler(canvas1_VisibleChanged);
I have tried the above but it doesn't work, anyone know how to do it ?
You're looking for the IsVisibleChanged event, which applies to ALL UIElements:
UIElement.IsVisibleChanged
More Information: IsVisible is a read-only Dependency Property. It is a calculated value, and the Visibility Dependency Property affects it. This is what you should use to detect if you're UIElement is visible or not.
Now, if you really really wanna just check for the Visibility DP changing for whatever reason there is a way to do so: http://agsmith.wordpress.com/2008/04/07/propertydescriptor-addvaluechanged-alternative/
Though, I'd still stick with just tracking the IsVisibleChanged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With