无法更改VisualStateManager转换持续时间

本文关键字:转换 持续时间 VisualStateManager | 更新日期: 2023-09-27 18:29:15

我为正在创建的控件定义了几个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秒(我假设是默认值)。

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

无法更改VisualStateManager转换持续时间

为了向同事证明这一点,我在每个可用的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>

我真的不确定其中哪些是必要的,哪些是多余的。