WPF Synchronized Animation and Dead End UI

I am writing a 3D wpf application using Viewport3D. When the user clicks the button, I have to start DoubleAnimation on AxisAngleRotation3D , but this should be done synchronously. I can't do this on animation.Completed because this animation starts the next and next recursively.

ButtonHandler should work with the user interface thread, because I hardly use Viewport3D to calculate the animation.

So, I have to start synchronous animation in the UI thread even after it has finished continuous work.

I tried this code, but it causes a dead end:

 AxisAngleRotation3D axis; DoubleAnimation animation; DependencyProperty dp; var worker = new Thread(() => { Dispatcher.CurrentDispatcher.InvokeShutdown(); Dispatcher.Run(); }); worker.SetApartmentState(ApartmentState.STA); worker.Start(); AutoResetEvent animationDone = new AutoResetEvent(false); EventHandler handler = null; handler = (sender, args) => { animation.Completed -= handler; // remove self animationDone.Set(); // signal completion }; animation.Completed += handler; Dispatcher.CurrentDispatcher.Invoke(new Action(() => { axis.BeginAnimation(dp, animation); })); animationDone.WaitOne(); 
+5
source share
1 answer

Ok, thatโ€™s just an idea. Why don't you create this animation in a few steps. First run the first batch of animations, and then when they finish launching another set of animations. You can synchronize it with some kind of timer.

You can first create a list of animations and objects to run at each step, and then just call them up.

+1
source

All Articles