我正在寻找一种解决方案来更改我后面的代码中的 TargetName 属性。我总共需要 9 种不同的图像/动画才能发生。在下面的示例中,只有 2 个。
这是 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>
在这里,您可以找到我在后面的代码中调用动画开始的方式
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");
}