在wp7中创建闪烁图像动画的最佳方法是什么?是否有可用源代码的示例? (要么) 我有一组4张图片,每一张都可以在几分之一秒内换到其他图像是否可能?
答案 0 :(得分:1)
我已经为你制定了这个代码。试试吧
在xaml中,添加一个带有图像控件和按钮的画布,其中有一个故事板
<Canvas Height="220" HorizontalAlignment="Left" Margin="79,29,0,0" Name="canvas1" VerticalAlignment="Top" Width="401" Grid.Row="1" >
<Canvas.Resources>
<Storyboard x:Name="myStoryboard">
<DoubleAnimation
Storyboard.TargetName="image"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1"
/>
</Storyboard>
</Canvas.Resources>
<Image Name="image" Width="200" Height="173"></Image>
<Button Content="Button" Height="54" HorizontalAlignment="Left" Margin="388,113,0,0" Name="button1" VerticalAlignment="Top" Width="97" Grid.Row="1" Click="button1_Click" Canvas.Left="-97" Canvas.Top="-26"/>
</canvas>
在代码隐藏事件中启动故事板事件
Set the image source to the first image when main page initialize. after that when click the button the blinking starts and change the images
private void button1_Click(object sender, RoutedEventArgs e)
{
myStoryboard.Begin();
myStoryboard.Completed +=new EventHandler(myStoryboard_Completed);
}
int count = 0;
public void myStoryboard_Completed(object sender, EventArgs e)
{
count++;
(if you are adding the images in a loop, try to pass the counter value in the source setter of image or else, here you said 4 images so for each counter value using if condition set the image source in whatever way use to set)
if(count == 1)
{
image.source = img.jpg
}
if(count == 2)
{
image.source = img2.jpg
}
if(count == 3)
{
image.source = img3.jpg
}
if(count > 3)
{
count ==0;
}
//start the story board again.the blink starts
myStoryboard.Begin();
}
Any doubts further kindly ask
答案 1 :(得分:0)
可以使用单张图像进行闪烁动画。
<Ellipse x:Name="light1" Grid.Column="1" Grid.Row="1" Fill="#FFF7810A" HorizontalAlignment="Left" Margin="109,9,0,8" Stroke="Black" Width="100" d:LayoutOverrides="GridBox"/>
<Ellipse x:Name="light2" Grid.Row="1" Fill="#FFF7810A" Margin="0,9,106,8" Stroke="Black" HorizontalAlignment="Right" Width="100" d:LayoutOverrides="GridBox"/>
在第二步中,我将动画应用于相反方向的两个圆圈,这样当一个淡入淡出时另一个淡出(对于两个闪烁的道路工作灯的幻觉)
<Grid.Triggers>
<EventTrigger RoutedEvent="Canvas.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="light1" Storyboard.TargetProperty="Opacity" From="0.5" To="1" Duration="0:0:1.5" AutoReverse="True" RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetName="light2" Storyboard.TargetProperty="Opacity" From="1" To="0.5" Duration="0:0:1.5" AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>