【问题标题】:Storyboard flicker between remove and begin故事板在删除和开始之间闪烁
【发布时间】:2013-09-02 21:06:48
【问题描述】:

我在 UserControl.Resources 中定义了这两个动画:

<Storyboard x:Key="pStatusExpand"
            AccelerationRatio=".4"
            DecelerationRatio=".4">
    <DoubleAnimation Storyboard.TargetProperty="Tag"
                        Duration="0:0:0.6" 
                        From="0" To="1"
                        />
</Storyboard>
<Storyboard x:Key="pStatusHide"
            AccelerationRatio=".4"
            DecelerationRatio=".4">
    <DoubleAnimation Storyboard.TargetProperty="Tag"
                        Duration="0:0:0.6" 
                        From="1" To="0"
                        BeginTime="0:0:0.5"
                        />
</Storyboard>

我使用以下触发器在它们所属的网格中为它们设置动画:

<Grid.Style>
    <Style TargetType="{x:Type Grid}">
        <Style.Triggers>
            <DataTrigger Value="true">
                <DataTrigger.Binding>
                    <MultiBinding Converter="{StaticResource MaxConverter}">
                        <Binding ElementName="self" Path="Items.Count" />
                        <Binding ElementName="self" Path="MaxCountItems" />
                    </MultiBinding>
                </DataTrigger.Binding>
                <DataTrigger.EnterActions>
                    <RemoveStoryboard BeginStoryboardName="Expand" />
                    <BeginStoryboard Name="Hide" Storyboard="{StaticResource pStatusHide}" />
                </DataTrigger.EnterActions>
            </DataTrigger>
            <DataTrigger Binding="{Binding ElementName=self, Path=Items.Count}" Value="0">
                <DataTrigger.EnterActions>
                    <RemoveStoryboard BeginStoryboardName="Hide" />
                    <BeginStoryboard Name="Expand" Storyboard="{StaticResource pStatusExpand}" />
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Grid.Style>

动画调整网格的高度:

<Grid.Height>
    <MultiBinding Converter="{StaticResource MultiplyConverter}">
        <Binding ElementName="self" Path="StatusHeight" />
        <Binding RelativeSource="{RelativeSource Self}" Path="Tag" />
    </MultiBinding>
</Grid.Height>

我遇到的问题是,在RemoveStoryBoard named Expand 之间,高度从其动画结束值 ~25 和BeginStoryBoard named Hide 之间设置为 0,当它开始将高度设置回全量以开始对其进行动画处理时降至 0。

换个说法:

  1. Expand 动画触发,因为 Items.Count 等于 0。它将网格的高度增长/动画到 25。
  2. 加载一直持续到...
  3. Items.Count 现在等于 MaxCountItems 触发第二个触发器(用于隐藏)
  4. Expand 动画已被移除(导致闪烁),但如果未移除 - Hide 动画不会执行任何操作(或似乎没有执行任何操作)。

闪烁似乎是,当移除展开并开始隐藏时,网格的高度会短暂设置为 0。

触发器有效,但我认为对于那些关心的人的一些注意事项与手头的问题无关:

  • self 是网格所在的 UserControl
  • StatusHeight 是一个依赖属性,默认为某个高度。
  • MaxConverter 检查是否Items.Count &gt;= MaxCountItems
  • MultiplyConverter 将 Tag 值与 StatusHeight 相乘,因此我可以将动画绑定到一个高度并避免冻结问题。注意,动画是从 0 到 1 和 1 到 0。

避免闪烁的想法?

【问题讨论】:

    标签: wpf xaml storyboard wpf-animation


    【解决方案1】:

    我有两个可能的建议给你,虽然它们只是……建议。第一个与您为pStatusHide Storyboard 设置的BeginTime 相关...如果您将其设置为0:0:0,那么它应该立即启动...也许半秒延迟是您看到闪烁的时候。

    另一个建议是将您的RemoveStoryboard 替换为StopStoryboard,甚至更好的是PauseStoryboard。这样,最后一个值将被保留,而不是(暂时)恢复为 0。

    【讨论】:

    • 这肯定是 BeginTime,很好。暂停没有帮助,但停止和删除都有帮助。不幸的是,我不得不增加隐藏的持续时间,但这确实有效。
    猜你喜欢
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 2012-01-11
    相关资源
    最近更新 更多