Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 18th, 2012  |  syntax: None  |  size: 2.68 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Blinking image animation in phone7
  2. <Canvas Height="220" HorizontalAlignment="Left" Margin="79,29,0,0" Name="canvas1" VerticalAlignment="Top" Width="401" Grid.Row="1" >
  3.         <Canvas.Resources>
  4.  
  5.             <Storyboard x:Name="myStoryboard">
  6.                 <DoubleAnimation
  7.     Storyboard.TargetName="image"
  8.     Storyboard.TargetProperty="Opacity"
  9.     From="1.0" To="0.0" Duration="0:0:1"
  10.      />
  11.             </Storyboard>
  12.  
  13.         </Canvas.Resources>
  14.  
  15.  
  16.         <Image Name="image" Width="200" Height="173"></Image>
  17.         <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"/>
  18.         </canvas>
  19.        
  20. 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
  21.  
  22.  
  23. private void button1_Click(object sender, RoutedEventArgs e)
  24.     {
  25.         myStoryboard.Begin();
  26.         myStoryboard.Completed +=new EventHandler(myStoryboard_Completed);
  27.     }
  28.  
  29.  
  30.    int count = 0;
  31.  
  32.    public void myStoryboard_Completed(object sender, EventArgs e)
  33.    {
  34.  
  35.        count++;
  36.  
  37.        (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)
  38.  
  39.        if(count == 1)
  40.          {
  41.             image.source = img.jpg
  42.          }
  43.  
  44.        if(count == 2)
  45.          {
  46.             image.source = img2.jpg
  47.          }
  48.        if(count == 3)
  49.          {
  50.             image.source = img3.jpg
  51.          }
  52.        if(count > 3)
  53.          {
  54.            count ==0;
  55.          }
  56.  
  57.        //start the story board again.the blink starts
  58.  
  59.          myStoryboard.Begin();
  60.  
  61.         }
  62.  
  63.         Any doubts further kindly ask
  64.        
  65. <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"/>
  66.  
  67. <Ellipse x:Name="light2" Grid.Row="1" Fill="#FFF7810A" Margin="0,9,106,8" Stroke="Black" HorizontalAlignment="Right" Width="100" d:LayoutOverrides="GridBox"/>
  68.        
  69. <Grid.Triggers>
  70. <EventTrigger RoutedEvent="Canvas.Loaded">
  71. <BeginStoryboard>
  72.     <Storyboard>
  73.         <DoubleAnimation Storyboard.TargetName="light1"        Storyboard.TargetProperty="Opacity" From="0.5" To="1" Duration="0:0:1.5"  AutoReverse="True" RepeatBehavior="Forever" />
  74.         <DoubleAnimation Storyboard.TargetName="light2"  Storyboard.TargetProperty="Opacity" From="1" To="0.5" Duration="0:0:1.5" AutoReverse="True" RepeatBehavior="Forever" />
  75.     </Storyboard>
  76. </BeginStoryboard>
  77.   </EventTrigger>
  78. </Grid.Triggers>