A A
RSS

Silverlight – Change the storyboard TargetName

Wed, Feb 6, 2008

Uncategorized

I wanted to reuse the same animation for multiple objects, which should have been a simple task.  Unfortunately, it took me a while to figure it out. 

In theory, all I should need to do is set the Storyboard.TargetName property to a different object and I am done.  I tried all kind of combinations and couldn’t get it to work.

Luckily, it’s a simple fix.  Do NOT add the TargetName in the XAML.  So your Storyboard might look like this:

<Storyboard x:Name=”sbMouseOver” >
  <ColorAnimation Storyboard.TargetProperty=”(Fill).(Color)”  To=”Red”  Duration=”0:0:00.1″/>
</Storyboard>

In your code, you can assign the storyboard to any object by, stopping it, setting the TargetName then starting it.  For example:

this.sbMouseOver.Stop();
this.sbMouseOver.SetValue<string>(Storyboard.TargetNameProperty, Rectangle2.Name);
this.sbMouseOver.Begin();

Tags:

Comments are closed.

Advertise Here
The Most Intelligent Add-In To Visual Studio Happy fan of

What I'm Doing...

Yonkly Open Source

Sign up for my newsletter




* = required field

powered by MailChimp!

megree Widget

Apparently, I am connected to Obama. Check this out...
My path to Obama

Cyber Identity