Skip to main content

Microsoft Silverlight

Answered Question dynamically insert a storyboard?RSS Feed

(0)

cdubone
cdubone

Member

Member

187 points

224 Posts

dynamically insert a storyboard?

Is there a way to dynamically change the content of a storyboard (double animations and such)? What I mean is I would like to have:
<Storyboard x:Name="Animation">                
</Storyboard>
hard coded into my application, and then on a button click insert some DoubleAnimationUsingKeyFrames. I'd also like to clear the content in order to insert more. Is this possible?

Chris Williams

mchlsync
mchlsync

Star

Star

14606 points

2,730 Posts

Silverlight MVP
Answered Question

Re: dynamically insert a storyboard?

 What about creating the entire storyboard object dynamically?

For example:

string sbdef = @"<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime='00:00:00' Storyboard.TargetName='text1' Storyboard.TargetProperty='(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)'>
<SplineDoubleKeyFrame KeyTime='00:00:00.5000000' Value='{0}'/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>";
double angle=0;
void Clicked(object sender, EventArgs e)
{
angle +=90;
Storyboard sb= (Storyboard) XamlReader.Load(String.Format(sbdef, angle));
this.Resources.Add (sb);
sb.Begin();
}

Ref: http://silverlight.net/forums/t/842.aspx 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

Regards,
Michael Sync
Silverlight MVP

Blog : http://michaelsync.net


cdubone
cdubone

Member

Member

187 points

224 Posts

Re: dynamically insert a storyboard?

Cool, thanks! I'm actually doing something very similar to this already. The difference is that I'm unpacking it from a zip (along with images and a media file). It turns out the problem I was having wasn't being caused by this as I thought, it was something totally different.

Thanks for the help! 

Chris Williams
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities