I have created an animation that takes 400 milliseconds to run, and attached it to an EventTrigger for the Loaded RoutedEvent of my Window.

But I think the window doesn't show up right away after it's loaded*, so I can't see the animation at all.

What are some common patterns for running animations when a Window loads?

And also, when should I run animations in separate threads?

* It probably draws the window after it is loaded and it shows the window after it's finished drawing, clarification would be helpful.

有帮助吗?

解决方案 2

I have tried the solutions suggested in the following answer:

https://stackoverflow.com/a/8886941/494094

  • Window.ContentRendered
  • UIElement.LayoutUpdated
  • Window.Activated

So far, Window.Activated event seems to suit me best. The only caveat is that none of those events are RoutedEvents, so you need to define the animation in the code behind like the following:

this.Activated += (sender, args) => ((Storyboard) FindResource("MyAnimation")).Begin();

其他提示

400 Miliseconds is pretty fast, so a loading window can take longer. I'd suggest keeping it in the same thread, but using a timer event.Timer Interval to delay it until the window is fully loaded.

I use the time events for splash screens, etc... and would do the same, I am sure, for a timed animation. It just takes a little practice. My suggestion is to use a long delay on the time to make sure it acts the way you want... then reduce the timer to put it where you want in the load screen.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top