Same animation for multiple target names

I just doubt it. I have three images in a WPF application. I am going to give a blinking effect for these 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 is for FirstImage (Img1). So I have to give for two other images. Can I give some names of taxis in previus encoding. Otherwise, I need to copy and paste the samecoding and change the target name. Is there a way to give a single coding?

+3
source share
2 answers

Storyboard.TargetNames DoubleAnimation, : , , , .

. , :

  • Visibility = "Collapsed", .
  • .

- DoubleAnimation WPF StoryBoard. , .

, , . .

+2

1. StaticResource DoubleAnimation. ( ):

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

2. Storyboard.TargetName RelativeSource Binding. :

<Image Name="img1">
      <Image.Triggers>
           <EventTrigger RoutedEvent="Image.Loaded">
                <BeginStoryboard  >
                    <Storyboard Storyboard.TargetName="{Binding Name,RelativeSource={RelativeSource AncestorType=Image,Mode=FindAncestor}}">
                        <StaticResourceExtension ResourceKey="DA" />
                    </Storyboard>
                </BeginStoryboard>
           </EventTrigger>
       </Image.Triggers>
 </Image>
0

Source: https://habr.com/ru/post/1732512/


All Articles