闪烁文本块样式抛出错误

时间:2011-11-11 14:59:54

标签: wpf xaml

我正在尝试在XAML中创建一个样式,可以应用于任何TextBlock元素以使文本闪烁。这是风格:

<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>

当我将其应用于文本块时

<TextBlock FontSize="16" FontStyle="Italic" FontWeight="Bold" Foreground="Red" Style="{StaticResource BlinkingTextBlock}" >

我收到错误:

Must have a Storyboard object reference before this trigger action can execute.

有没有人知道我需要另一个故事板?

1 个答案:

答案 0 :(得分:1)

错误说明了一切,你应该绑定到“FlashMe”StoryBoard

<BeginStoryboard  Storyboard= "{StaticResource FlashMe}" />