I have a StackPanel from which I want to remove an element. Prior to removing the element, I want to perform an animation on the element to signal the element is about to be removed. However, performing the animation followed up by removing the element causes the element to remove immediately, with no visible animation. Is there a correct way to do this?
StackPanel myStackPanel = new StackPanel();
// myStackPanel is loaded with visible elements here.
// Time to remove an element!
MyUserControl control = myStackPanel.Children[0] as MyUserControl;
control.SomeAnimation.Begin();
myStackPanel.Children.Remove(control);
UPDATE I ended up doing the following ugliness to get this working as hoped:
control.SomeAnimation.Begin();
Thread t = new Thread(delegate()
{
Thread.Sleep(500);
Dispatcher.BeginInvoke( () => myStackPanel.Children.Remove(control));
});
t.Start();