Preli
Preli

Reputation: 3041

Silverlight animation starts too early

I have a Silverlight animation:

<Storyboard x:Key="CloseAnimation" x:Name="CloseAnimation" Storyboard.TargetName="nv" Storyboard.TargetProperty="Height">
  <DoubleAnimation x:Name="CloseAnimation1" Duration="0:0:5" From="30" To="0">
  </DoubleAnimation>
</Storyboard>

and following code which is executed when a button is clicked:

MessageBox.Show("Test");
CloseAnimation.Begin();

I would expect the animation to start when the line CloseAnimation.Begin(); gets executed and then last for the specified duration. But it seems as if the time for displaying the animation would be measured from the button click. If the MessageBox is visible for let's say 3 seconds - this time is subtracted from the animation and only the remaining animation is shown.

Why and how can I prevent this?

Upvotes: 2

Views: 103

Answers (1)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93631

Basically the animation is starting based on the current frame's time, not actual time.

By delaying the start of the animation, with a modal MessageBox, time has passed since the first frame's start time and it does its usual catchup/interpolation.

Don't call animation Begin() in the same thread as a modal messagebox. Use a button in a popup to trigger the animation rather than use any modal dialogs.

Upvotes: 1

Related Questions