im searching for a solution to change the TargetNameproperty in my code behind. in total i need 9 different images / animations to happen. in the example below there are just 2.
here is the XAML
<Storyboard x:Name="MyAnimationBoard1" x:Key="MyAnimationBoard">
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="Anim1"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/>
<LinearDoubleKeyFrame Value="30" KeyTime="0:0:0.5"/>
<LinearDoubleKeyFrame Value="-30" KeyTime="0:0:0.10"/>
<LinearDoubleKeyFrame Value="30" KeyTime="0:0:0.20"/>
<LinearDoubleKeyFrame Value="-30" KeyTime="0:0:0.30"/>
<LinearDoubleKeyFrame Value="30" KeyTime="0:0:0.40"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="Anim2"
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)">
<LinearDoubleKeyFrame Value="0" KeyTime="0:0:4"/>
<LinearDoubleKeyFrame Value="30" KeyTime="0:0:4.5"/>
<LinearDoubleKeyFrame Value="-30" KeyTime="0:0:4.10"/>
<LinearDoubleKeyFrame Value="30" KeyTime="0:0:4.20"/>
<LinearDoubleKeyFrame Value="-30" KeyTime="0:0:4.30"/>
<LinearDoubleKeyFrame Value="30" KeyTime="0:0:4.40"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
Here you find the way i call the animations to begin in code behind
if (timesTicked == 59)
{
string voedsel = "Food1";
Animate.AnimateFood(voedsel);
//Would be nice to call the correct tagretname first.
MyAnimationBoard1.Begin();
}
else if (timesTicked == 52)
{
string voedsel = "Food3";
Animate.AnimateFood(voedsel);
Debug.WriteLine("Tweede animatie");
}
else if (timesTicked == 46)
{
string voedsel = "Food8";
Animate.AnimateFood(voedsel);
Debug.WriteLine("Derde animatie");
}
You could use Storyboard.SetTargetName(Timeline, String) Method to change the value of
TargetName
property of aDoubleAnimation
dynamically. You need to add aName
for everyDoubleAnimationUsingKeyFrames
.For example: