Ho un progetto WPF con un bordo che utilizza il seguente stile. Il piano è di far sbiadire l'effetto bagliore quando il mouse si sposta oltre il bordo e scompare quando esce.Come animare Opacity di DropShadowEffect?
<Style x:Key="BorderGlow" TargetType="Border">
<Style.Resources>
<Storyboard x:Key="GlowOn">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(DropShadowEffect.Opacity)">
<SplineDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="GlowOff">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(DropShadowEffect.Opacity)">
<SplineDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Style.Resources>
<Setter Property="CornerRadius" Value="6,1,6,1" />
<Setter Property="BorderBrush" Value="{StaticResource SelectedBorder}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Background" Value="{StaticResource DeselectedBackground}" />
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
<Setter Property="TextBlock.Foreground" Value="{StaticResource SelectedForeground}" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="90"/>
</Setter.Value>
</Setter>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" BlurRadius="8" Color="#FFB0E9EF"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource GlowOn}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource GlowOff}"/>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
Il problema è che non succede niente! L'animazione funziona se cambio "DropShadowEffect" in "UIElement" nello Storyboard TargetProperty, ma questo sfuma l'intero controllo.
Come faccio a dissolvere solo DropShadowEffect?
ottengo un InvalidOperationException perché Effetto doesn' t avere una proprietà Opacity. Il valore di Effect è DropShadowEffect che ha la proprietà Opacity che sto cercando di targetizzare, ma come fai notare il mio XAML è sbagliato. Ho provato a impostare x: Name su DropShadowEffect ma non puoi usare TargetName in Stili. C'è un buco nella documentazione MSDN sull'uso di queste parentesi nello storyboard, ma l'ho rintracciato nella guida di PropertyPath. Tuttavia non riesco ancora a risolvere il problema. Penso di aver bisogno di lanciare Effect su DropShadowEffect ma questo non sembra possibile in XAML. Qualche altra idea? – Zodman
Sono riuscito a ottenere il codice che hai postato funzionante usando la sintassi che ho fornito, l'ho fatto in un'app campione spogliata. Pubblicherò quello che ho usato e forse puoi tornare indietro da quello ... –
Nota Ho rimosso i setter che usano risorse statiche che non hai fornito ma che non effettueranno la dimostrazione. E noto che stai cercando di impostare TextBlock. Proprietà di primo piano nel tuo stile che non funzionerà. –