This is my custom button:
<Style TargetType="local:AnswerButton">
<Setter Property="Background" Value="{StaticResource BlueGradient}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:AnswerButton">
<Grid>
<Border BorderBrush="Blue" BorderThickness="2" CornerRadius="10">
<Border Name="myBorder" Background="{TemplateBinding Background}" CornerRadius="9">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
TextAlignment="Center" VerticalAlignment="Center"
Text="{TemplateBinding Option}" Foreground="Yellow" />
<TextBlock Grid.Column="1"
TextAlignment="Left" VerticalAlignment="Center"
Text="{TemplateBinding Text}" Foreground="Black" />
</Grid>
</Border>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
How can I set animation for custom button? I tried this:
ColorAnimation myColorAnimation = new ColorAnimation();
myColorAnimation.From = Colors.Blue;
myColorAnimation.To = Colors.Green;
myColorAnimation.AutoReverse = true;
myColorAnimation.Duration = TimeSpan.FromSeconds(1);
Storyboard.SetTargetName(myColorAnimation, "myBorder");
Storyboard.SetTargetProperty(myColorAnimation,
new PropertyPath(Border.BackgroundProperty));
Storyboard myStoryboard = new Storyboard();
myStoryboard.Children.Add(myColorAnimation);
myStoryboard.Begin();
But it has problem with target name. I know it's wrong but how can I set target to custom control? I have 4 in my page and I want to set this animation for one which is choosed:
<Controls:AnswerButton Name="btnAnswerA" Tap="AnswerButton_Tap"/>
<Controls:AnswerButton Name="btnAnswerB" Tap="AnswerButton_Tap"/>
<Controls:AnswerButton Name="btnAnswerC" Tap="AnswerButton_Tap"/>
<Controls:AnswerButton Name="btnAnswerD" Tap="AnswerButton_Tap"/>
I don't care if it would be in code or in xaml but how can I get some of that custom buttons blinking (flashing) by coloranimation? Thanks
Edit: I tried many options with visualstatemanager like in Thaven's answer but it didn't help. Really there is no one who knows where could be possible problem?