A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
Hello @RogerSchlueter-7899 ,
Thanks for your question.
The problem is x:Name="AddButtonBackgroundBrush" on your brush. When you give the brush its own name, WPF registers it as an independent object in the namescope. So when the Storyboard tries to reach the color through the Button path (TargetName="btnAdd" → Button.Background → Color), WPF gets confused because the brush thinks it belongs to itself, not the Button anymore, and the animation silently fails.
On top of that, FillBehavior="Stop" + the Completed handler replaces the background with a brand new unnamed brush, so even if the first animation worked, the second click would fail because the original brush is gone.
You can refer to code example below:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test Storyboard" Height="200" Width="300"
Loaded="Window_Loaded">
<Window.Resources>
<Storyboard x:Key="sbSuccess">
<ColorAnimation
Storyboard.TargetName="btnAdd"
Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)"
From="#ff1493"
To="Green"
Duration="0:0:2"/>
</Storyboard>
</Window.Resources>
<Grid>
<Button x:Name="btnAdd"
Content="Button"
Width="160" Height="50"
Click="AddStandardEntry">
<Button.Background>
<SolidColorBrush Color="#ff1493"/>
</Button.Background>
</Button>
</Grid>
</Window>
Imports System.Windows.Media.Animation
Class MainWindow
Private sbSuccess As Storyboard
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
sbSuccess = CType(Me.FindResource("sbSuccess"), Storyboard)
End Sub
Private Sub AddStandardEntry(sender As Object, e As RoutedEventArgs) Handles btnAdd.Click
sbSuccess.Begin()
End Sub
End Class
Please feel free to reach out if you have concerns.
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.