2012-06-18 85 views
0

在wp7中创建闪烁图像动画的最佳方式是什么?有源代码样本吗? (或) 我有一套4张图片,每一张图片都可以在几秒钟内变成其他图片,这有可能吗?在phone7中闪烁图像动画

回答

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> 
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