I want to animate button shadow effect color when mouse enter border.
I try this code and is not working for me.
And I don’t know where is the problem is?
<Style x:Name="HeaderButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Border" BorderBrush="#FF550211" BorderThickness="0" CornerRadius="4">
<Border.Triggers>
<EventTrigger RoutedEvent="Border.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Color" Storyboard.TargetName="MenuButtonShadow"
From="#FFFFFFFF" To="#FF000000" Duration="0:0:0.3"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFAF1232" Offset="0" />
<GradientStop Color="#FFB60329" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<ContentPresenter Margin="8, 0" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect x:Name="MenuButtonShadow" ShadowDepth="0" BlurRadius="4"></DropShadowEffect>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Margin" Value="4"></Setter>
</Style>
From MSDN:
I imagine you could do something like this in your XAML (though I haven’t tested it):
And then your event handler would call the Begin method on the storyboard:
You’ll probably want to add something similar for the MouseLeave event, which makes the color go back to #FFFFFFFF.