开发者

WPF canvas VisibilityChanged event

开发者 https://www.devze.com 2023-03-19 13:52 出处:网络
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 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, 开发者_如何学Goanyone 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.


The normal WPF Canvas object does not have a .VisibleChanged event, so you can't assign an event handler to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号