2015-04-19 1 views
0

J'ai créé un bouton avec effet Ombre portée. Maintenant je veux ajouter une animation pour cet effet en changeant la propriété d'opacité pendant l'exécution. Mais ce code ne fonctionne pas:Modification de l'opacité Propriété de bouton WPF à l'aide de l'animation

<Button x:Name="btnRun" Content="Run" Click="btn_RunEventHandler" BorderThickness="1" > 
         <Button.Effect> 
          <DropShadowEffect Color="Red" ShadowDepth="0" BlurRadius="21" /> 
         </Button.Effect> 
         <Button.Triggers> 
          <EventTrigger RoutedEvent="Button.MouseEnter"> 
           <EventTrigger.Actions> 
            <BeginStoryboard> 
             <Storyboard> 
              <DoubleAnimationUsingKeyFrames 
               Storyboard.TargetProperty="(DropShadowEffect.Opacity)" 
               Duration="0:0:1.6" 
               RepeatBehavior="Forever"> 
               <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1"/>              
               <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/> 
               <LinearDoubleKeyFrame KeyTime="0:0:0.55" Value="0"/> 
               <LinearDoubleKeyFrame KeyTime="0:0:0.6" Value="1"/> 
               <LinearDoubleKeyFrame KeyTime="0:0:0.7" Value="1"/> 
               <LinearDoubleKeyFrame KeyTime="0:0:0.8" Value="0.6"/> 
               <LinearDoubleKeyFrame KeyTime="0:0:1" Value="1"/> 
               <LinearDoubleKeyFrame KeyTime="0:0:1.6" Value="1"/> 
              </DoubleAnimationUsingKeyFrames>             
             </Storyboard> 
            </BeginStoryboard> 
           </EventTrigger.Actions> 
          </EventTrigger> 
         </Button.Triggers> 
        </Button> 

Répondre

3

Donnez votre DropShadow un nom

<DropShadowEffect Color="Red" x:Name="dropShadow" ShadowDepth="0" BlurRadius="21" /> 

et animez Opacity de cette TargetName

<DoubleAnimationUsingKeyFrames 
    Storyboard.TargetName="dropShadow" 
    Storyboard.TargetProperty="Opacity" 
    .../> 
+0

Il fonctionne très bien, merci. – SwitchOn