I am implementing a “marching ants” style animation by applying a StrokeDashOffset animation to a Rectangle control. I would like the animation to play when the rectangle is visible but not take up extra CPU cycles when it’s hidden. Is WPF smart enough to automatically pause the animation when the affected control is hidden?
I am implementing a marching ants style animation by applying a StrokeDashOffset animation to
Share
No. WPF is smart enough to not do so :). The reason behind this is that the animation system cannot make assumptions about what the animated property does (it could be any dependency property, not necessary related to control appearance, in which case you want the animation to work regardless of visibility).
You can test this as follows:
XAML:
C#:
You’ll see proof of WPF’s brilliance in the debug output: it shows
DoublePropertychanges whether the control is visible or not, but visibility matters when it comes to Measure/Arrange. Handlers are not called when the control is collapsed, even though I markedDoublePropertyas a property that affects measure and arrange…