Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF canvas VisibilityChanged event

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 ?

like image 497
Welsh King Avatar asked Jul 09 '11 13:07

Welsh King


1 Answers

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.

like image 83
myermian Avatar answered Oct 06 '22 05:10

myermian