我有以下应该工作的:
XAML
<Window.Resources>
<Storyboard x:Name="FadeInStoryboard1">
<FadeInThemeAnimation Storyboard.TargetName="Image1" />
</Storyboard>
<Storyboard x:Name="FadeInStoryboard2">
<FadeInThemeAnimation Storyboard.TargetName="Image2" />
</Storyboard>
<Storyboard x:Name="FadeInStoryboard3">
<FadeInThemeAnimation Storyboard.TargetName="Image3" />
</Storyboard>
<Storyboard x:Name="FadeInStoryboard4">
<FadeInThemeAnimation Storyboard.TargetName="Image4" />
</Storyboard>
<Storyboard x:Name="FadeInStoryboard5">
<FadeInThemeAnimation Storyboard.TargetName="Image5" />
</Storyboard>
</Window.Resources>
<Image Source="../Assets/image.png" x:Name="Image1" />
<Image Source="../Assets/image.png" x:Name="Image2" />
<Image Source="../Assets/image.png" x:Name="Image3" />
<Image Source="../Assets/image.png" x:Name="Image4" />
<Image Source="../Assets/image.png" x:Name="Image5" />
C#
//fades in the plane image
private void FadeIn(int Index)
{
if (Index == 0)
FadeInStoryboard1.Begin();
else if (Index == 1)
FadeInStoryboard2.Begin();
else if (Index == 2)
FadeInStoryboard3.Begin();
else if (Index == 3)
FadeInStoryboard4.Begin();
else
FadeInStoryboard5.Begin();
}
上面的代码有效——但必须有更好的方法。有没有办法 (A) 将 Storyboard 对象放入我可以通过索引访问的列表中,或者 (B) 将 Storyboard 对象附加到作为其目标的 Image 对象上?