我和Silverlight玩得不亦乐乎,试图找出如何让它运转起来,有一件事我似乎不太懂,关于故事板和按需启动的行为。下面描述了一个蓝色椭圆,它在Y轴上有一个变换Y轴投影,因此当触发时,它看起来像一个在其垂直轴上旋转的3D圆。单击椭圆时触发该行为。如果RepeatBehavior设置为3x,那么它将重复三次并停止。
我想弄清楚的是,每次单击椭圆时,如何使此行为重新激发,因为在行为第一次运行后,它不会再次激发。我试图通过创建一个MouseLeftButtonDown事件并填充
Storyboard1.Begin();
但这没用。事实上,如果我在那里设置断点,它确实会执行,但没有效果。下面是Xaml:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" mc:Ignorable="d"
x:Class="UsingStoryboards.MainPage"
Width="640" Height="480">
<UserControl.Resources>
<Storyboard x:Name="Storyboard1" RepeatBehavior="3x">
<DoubleAnimation Duration="0:0:2" To="160" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="ellipse" d:IsOptimized="True"/>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<ei:ChangePropertyAction PropertyName="Background">
<ei:ChangePropertyAction.Value>
<SolidColorBrush Color="#FFE50D0D"/>
</ei:ChangePropertyAction.Value>
</ei:ChangePropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<Ellipse x:Name="ellipse" Fill="#FF000BF5" HorizontalAlignment="Left" Height="80" Margin="54,75,0,0" Stroke="Black" VerticalAlignment="Top" Width="80" MouseLeftButtonDown="ellipse_MouseLeftButtonDown">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Ellipse.Projection>
<PlaneProjection/>
</Ellipse.Projection>
</Ellipse>
</Grid>
</UserControl>