I’m developing an application in WPF and .Net 4 which contains animations.
My controls are bound to certain values in the business logic, which toggles animations under certain conditions. The problem I am encountering is that those animations may play as soon as the application launches, which makes controls “animate” toward their initial state when first displayed.
Let’s say for example that I am developing the Login portion of the application. I have a control that represents a custom popup which should appear above the username and password fields if these are invalid. When the application launches, both those fields are invalid by default which prompts the popups to be displayed through an animation. I would like to prevent these animations from playing at start-up, without disabling them explicitly.
Another example to demonstrate my problem would be a toggle button bound to a boolean Property. If I saved the state of the button as being toggled prior to closing the application, the button would “animate” towards the toggled state when the application re-launches (since I have an animation between toggled states), instead of simply being toggled on without animating.
Is there a way to temporarily disable all animations from playing ?
I read somewhere that the best way to disable an animation is to call SkipToFill(…) on a particular Storyboard. The problem with that is that I have to explicitly disable all animations concerned, which may be a problem if these are not known beforehand.
Storyboard theBoard = (Storyboard)FindResource(resourceName);
theBoard.Begin(this, true);
theBoard.SkipToFill(this);
How would you go about disabling animations without explicitly disabling them one by one ? Is such a thing even possible ?
What about using an attached dependency property (attached on StoryBoards) that would enable or disable your animations (or set their duration to 0) ? Maybe there’s a simpler solution but since none seems to be proposed, i suggest that one.
Rq : i’m not sure the controls beeing animated on window opening is a very boring thing. But i don’t know, maybe if there’s a lot of animation on the screen, maybe it can look strange.