I’m trying to create a style in XAML that can be applied to any TextBlock element to make the text blink. Here is the style:
<Style x:Key="BlinkingTextBlock" TargetType="TextBlock">
<Style.Resources>
<Storyboard x:Key="FlashMe" RepeatBehavior="Forever">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="0:0:0.5">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:1">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</Style.Resources>
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard x:Name="FlashMe" />
</EventTrigger>
</Style.Triggers>
</Style>
When I apply it to a text block
<TextBlock FontSize="16" FontStyle="Italic" FontWeight="Bold" Foreground="Red" Style="{StaticResource BlinkingTextBlock}" >
I get an error:
Must have a Storyboard object reference before this trigger action can execute.
Does anyone have an idea of where I need another storyboard?
The error says it all, you should bind to the “FlashMe”
StoryBoard: