[英]Silverlight Add an animation to an image in the style.xaml
I got a button, that display an image. 我有一个按钮,显示一个图像。 I want to add, to this image, an animation, so that it will blink (so the user can't ignore it). 我想在此图像上添加动画,使其闪烁(以便用户无法忽略它)。
So I tried this in the style.xaml : 所以我在style.xaml中尝试了这个:
<Style x:Key="WarningIcon" TargetType="Button">
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="30"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid>
<Image Source="../images/im_warning.png" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Visibility">
<Setter.Value>
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty="(Button.Visibility)"
Duration="5:0:0.5"
RepeatBehavior="Forever"/>
</Storyboard>
</Setter.Value>
</Setter>
</Style>
But it doesn't work. 但这是行不通的。
What kind of animation, and setter should I add to make the image blinking, so basically, appear and desappear? 我应该添加哪种动画和设置器,以使图像闪烁,因此基本上消失并消失?
I do not find any example that match with my research. 我找不到任何与我的研究相符的例子。
Thank you. 谢谢。
You should start animation after defining it. 您应该在定义动画后开始动画。 Another thing is that probably Opacity
will look better: 另一件事是, Opacity
可能看起来会更好:
<Style
...
<Style.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Image.Opacity)"
BeginTime="0:0:0" Duration="0:0:0.5"
From="1.0" To="0.0" RepeatBehavior="Forever" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
...
</Style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.