同样的动画多目标名称 [英] Same animation for multiple Target Name

查看:144
本文介绍了同样的动画多目标名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个doubt.I在我的WPF application.Im三个图像会给出三个images.So我为这个code眨眼的效果。

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>

这一个是FirstImage(IMG1)。所以我不得不放弃了另外两个images.Can我给在previus编码多个taget名。
否则,我要复制并粘贴samecoding和改变TARGETNAME。
有什么办法在单编码给?

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?

推荐答案

您不能把多个Storyboard.TargetNames在DoubleAnimation是,但有一个更好的办法:使用数据绑定三个不透明度值绑定在一起,然后进行动画只有一个他们与其他人将发生变化。

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.

请注意:为了避免在创建绑定的不对称性可能要使用此附加tecnhique:

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


  1. 创建第四控制能见度=坍塌,所以你永远不会看到它

  2. 动画此控件的不透明度

  3. 绑定所有的三个可见控件不透明度为无形之一的透明度。

另一种选择是使用一个单一的DoubleAnimation是和使用code后面将它应用到所有三个图像,而不是使用WPF的故事板​​的机制。这给了你更多的控制,但需要您编写C-背后的$ C $。

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.

这篇关于同样的动画多目标名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆