I'm loading user controls in a specific grid in our application and I'm adding animations to the loading user controls in the Loaded
event handler of the controls.
Some of the user controls are lightweight and some of them need heavy computations before loading. The problem is that when I add a 1 second animation to the heavy user controls then showing the control so endures that the animation never can be seen!
Is there any other event that I can add my animation to the user control so that the heavy ones and the light ones get displayed with the same animation?
I need an event right before showing the control. OnLoaded
doesn't seem to be right place for me, unfortunately.
The answer was giving the Storyboard.Begin a lower priority.
I found out it from this answer : https://stackoverflow.com/a/4708172/970420
So we have this code for beginning the animation :
void BeginStoryboardAction(Storyboard sb)
{
sb.Begin();
}
and we should call it by this way :
Dispatcher.BeginInvoke(new Action<Storyboard>(BeginStoryboardAction), DispatcherPriority.ContextIdle, sb);
sb is an instance of Storyboard which has some animations in it.
[Edit] : Another shorter way :
Dispatcher.BeginInvoke(new Action<Storyboard>(delegate (Storyboard stb){stb.Begin();}), DispatcherPriority.ContextIdle, sb);
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