【问题标题】:XAML Storyboard Fadein - Fadeout Opacity LoopXAML Storyboard Fadein - 淡出不透明度循环
【发布时间】:2011-11-24 05:10:26
【问题描述】:

在我的 WPF 应用程序中,我有一个正在自定义 ItemTemplate 的 ListBox。在我的 ItemTemplate 中,我有一个选定项目的边框,我使用 StoryBoard 从 0 - 1 淡入/淡出,然后是 1 - 0。

我现在正试图弄清楚如何让它循环。

当不透明度值为 0 时,我尝试简单地添加第二个触发器属性,但这最终适用于列表框中的所有项目,而不仅仅是选定的项目。

<Storyboard x:Key="FadeUpAndFlash">
<DoubleAnimation From="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="0:0:1" FillBehavior="Stop"/></Storyboard>


<Border x:Name="HighlightBorder" BorderBrush="Yellow" BorderThickness="3" Margin="0,0,5,0" CornerRadius="10" ClipToBounds="True">
<Border.Style>
    <Style TargetType="{x:Type Border}">
        <Setter Property="Opacity" Value="0"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
                <DataTrigger.Setters>
                    <Setter Property="Opacity" Value="1"/>
                </DataTrigger.Setters>
                <DataTrigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource FadeUpAndFlash}" Name="AnimateImageBorder" />
                </DataTrigger.EnterActions>
            </DataTrigger>
            <Trigger Property="Opacity" Value="1">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:2"/>
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
            </Trigger>
        </Style.Triggers>
    </Style>
</Border.Style>

有什么想法可以让故事板循环播放吗?

【问题讨论】:

    标签: wpf xaml opacity storyboard


    【解决方案1】:

    在您的DoubleAnimation 中使用AutoReverse="True"
    还有RepeatBehavior="Forever",如果你想让它无穷无尽。

    【讨论】:

      猜你喜欢
      • 2013-11-14
      • 2012-05-24
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多