views:

176

answers:

1

Hi, Just a doubt.I have three images in my WPF application.Im going to give blink effect for that three images.So i gave this code.

<Storyboard x:Key ="AlarmBlink">
       <DoubleAnimation
            Storyboard.TargetName="Img1"
            Storyboard.TargetProperty="Opacity"
      From="1" To="0" Duration="0:0:0.1" 
      AutoReverse="True" RepeatBehavior="Forever" />
    </Storyboard>

This one is for FirstImage(Img1).So i have to give for other two images.Can i give multiple taget name in previus coding. Otherwise i have to copy and paste the samecoding and changing targetname. Is there any way to give in single coding?

A: 

You cannot put multiple Storyboard.TargetNames in a DoubleAnimation, but there is a better way: Use data binding to bind the three Opacity values together, then animate just one of them and the others will change as well.

Note: To avoid asymmetry in creating your bindings you may want to use this additional tecnhique:

  1. Create a fourth control with Visibility="Collapsed" so you never see it
  2. Animate this control's opacity
  3. Bind the Opacity of all three visible controls to the opacity of the invisible one.

Another option is to use a single DoubleAnimation and use code behind to apply it to all three images instead of using WPF's StoryBoard mechanism. This gives you much more control but requires you to write the code-behind.

Generally I stick with the binding solution because it is simplest. In any case the cut-and-paste solution is usually the worst of all.

Ray Burns