0

在 wp7 中创建闪烁图像动画的最佳方法是什么?是否有可用的源代码示例?(或)我有一组 4 张图像,每张图像都可以在几分之一秒内更改为其他图像,这可能吗?

4

2 回答 2

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
于 2012-06-18T09:25:53.320 回答
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>
于 2012-06-22T04:25:48.357 回答