Sha*_*ihi 4 xaml silverlight-2.0
好吧,正如标题所示:
我有一个故事板,我希望它的动画能够在没有代码干预的情况下启动.这个要求的原因是我的目标是Silverlight Embedded,我现在也懒得重新编译我的应用程序.并且,考虑到它,将来更容易更改动画.
XAML是否有一个属性可以在xaml加载后立即运行故事板?
Arc*_*rus 15
您可以使用Loaded事件来启动故事板
有关示例,请参阅MSDN: Storyboard(Silverlight)
从MSDN中挑选了这个例子:
<Canvas
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Rectangle
x:Name="MyAnimatedRectangle"
Width="100"
Height="100"
Fill="Blue">
<Rectangle.Triggers>
<!-- Animates the rectangle's opacity.
This is the important part, the EventTrigger which will start our animation -->
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MyAnimatedRectangle"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:5" AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
对象Rectangle具有属性.在Triggers属性中,我们定义了一个EventTrigger,它将在发生此事件时触发.我们选择Rectangle.Loaded事件,这意味着它会在加载时触发;).
我们添加一个BeginStoryboard属性来开始我们的故事板,并添加一个Storyboard.此动画将在Opacity属性上使用DoubleAnimation,这意味着在5秒的持续时间内,不透明度将逐渐淡化为零,然后返回(AutoReverse属性),它将永远执行此操作(RepeatBehaviour属性).