【问题标题】:Unable to change VisualStateManager transition duration无法更改 VisualStateManager 过渡持续时间
【发布时间】:2014-11-04 23:21:28
【问题描述】:

我已经为我正在创建的控件定义了一些 VisualStates 以淡入叠加层(“ThankYouOverlay”)并带有一条消息:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="CommonStates">
        <VisualStateGroup.Transitions>
            <VisualTransition To="ThankYou" GeneratedDuration="0:0:0.3">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Opacity)" To="1" />
                </Storyboard>
            </VisualTransition>
        </VisualStateGroup.Transitions>
        <VisualState x:Name="Normal">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}"/>
                </ObjectAnimationUsingKeyFrames>
                <DoubleAnimation Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Opacity)" To="0"/>
            </Storyboard>
        </VisualState>
        <VisualState x:Name="ThankYou">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
                </ObjectAnimationUsingKeyFrames>
                <DoubleAnimation Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Opacity)" To="1"/>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

此过渡有效,但我无法更改动画持续时间。我玩过 VisualTransitionGeneratedDuration 属性和单个动画的 Duration 属性的不同组合,但不管这些变化如何,动画的实际持续时间持续 1 秒(默认值,我假设)。

我错过了什么?如何更改过渡的持续时间?

【问题讨论】:

    标签: c# wpf xaml animation visualstatemanager


    【解决方案1】:

    为了尝试向同事证明这一点,我在 每个 可用的 Duration 属性上指定了一个 Duration... 然后它按我预期的方式工作:

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <VisualStateGroup.Transitions>
                <VisualTransition To="ThankYou" GeneratedDuration="0:0:0.3">
                    <Storyboard Duration="0:0:0.3">
                        <ObjectAnimationUsingKeyFrames Duration="0:0:0.3" Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Opacity)" To="1" />
                    </Storyboard>
                </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="Normal">
                <Storyboard Duration="0:0:0.3">
                    <ObjectAnimationUsingKeyFrames Duration="0:0:0.3" Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Opacity)" To="0"/>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="ThankYou">
                <Storyboard Duration="0:0:0.3">
                    <ObjectAnimationUsingKeyFrames Duration="0:0:0.3" Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Visibility)">
                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="ThankYouOverlay" Storyboard.TargetProperty="(UIElement.Opacity)" To="1"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    

    我不太确定哪些是必要的,哪些是多余的。

    【讨论】:

    • 您的 VisualTransition Generated Duration 只处理从一个状态移动到另一个状态所需的时间。但是,您在情节提要上的持续时间将应用于该实际动画。
    猜你喜欢
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 2021-08-12
    • 2019-01-25
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多