我在 Silverlight 中有三个 UserControl。
UCOutside 包含两个名为 UCInside1 和 UCInside2 的用户控件。
包含用户控件
<!-- UCOutside -->
<UserControl.Resources>
<Storyboard x:Name="OutsideBoard">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="LayoutRoot">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="45"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<local:UCInside1 Margin="39,35,266,173"/>
<local:UCInside2 HorizontalAlignment="Right" Margin="0,234,26,30" />
</Grid>
里面的第一个 UserControl
<!-- UCInside1 -->
<UserControl.Resources>
<Storyboard x:Name="ImageFade">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="myImage">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.2"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Image x:Name="myImage" Margin="0" Source="/OtherImage.png" Stretch="Fill" Width="312" Height="250" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
里面的第二个 UserControl
<!-- UCInside2 -->
<UserControl.Resources>
<Storyboard x:Name="ButtonFade">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="image1">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left" Height="195" VerticalAlignment="Top" Width="218">
<Button Content="Button" HorizontalAlignment="Right" Margin="0,0,25,51" VerticalAlignment="Bottom" Width="75" Click="ClickButton"/>
<Image x:Name="image1" HorizontalAlignment="Left" Margin="41,32,0,70" Source="/Whatever.png" Stretch="Fill" Width="47"/>
</Grid>
您会注意到 Button 上的 ClickButton 事件。您还会注意到所有用户控件中都指定了简单的故事板。
问题是如何让所有三个动画都通过点击事件开始?是否可以通过 XAML 或使用 Blend 将其全部绑定?如果不是,它是如何在 c# 代码中完成的?