【问题标题】:Storyboard to alternate Opacity between two controls故事板在两个控件之间交替不透明度
【发布时间】:2011-11-29 08:58:20
【问题描述】:

我正在尝试设计一个基于 XAML 的 StoryBoard,它可以在两个 Label 控件之间交替不透明度。

例如

标签 1 和标签 2。加载窗口时,Label2 默认不透明度设置为 0。

我想达到这样的目标:

Label1 = 不透明度 1(暂停 10 秒) 淡出 Label1

当 Label1 为 Opacity 0 时,Label2 淡入(再次暂停 10 秒) 淡出 Label2

然后循环这个。

我尝试使用绑定在两个标签之间的 Storyboard Repeats、AutoReverse 和 DataTriggers,但我似乎无法让它以这种方式运行。

【问题讨论】:

    标签: wpf storyboard


    【解决方案1】:

    您可以为每个标签使用关键帧动画,类似这样

    <Label Content="LABEL1" Name="Label1">
    <Label.Triggers>
        <EventTrigger RoutedEvent="Label.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" RepeatBehavior="Forever">
                            <LinearDoubleKeyFrame Value="1" KeyTime="0:0:10"></LinearDoubleKeyFrame>
                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:11"></LinearDoubleKeyFrame>
                            <LinearDoubleKeyFrame Value="0" KeyTime="0:0:22"></LinearDoubleKeyFrame>
                            <LinearDoubleKeyFrame Value="1" KeyTime="0:0:23"></LinearDoubleKeyFrame>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>
        </EventTrigger>
    </Label.Triggers>
    

    【讨论】:

    • 太棒了!还没玩过关键帧。谢谢大家。
    猜你喜欢
    • 2011-02-07
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    相关资源
    最近更新 更多