gpt4 book ai didi

wpf - VisualStateManager 无法为 ThicknessAnimations 生成过渡

转载 作者:行者123 更新时间:2023-12-04 21:20:30 26 4
gpt4 key购买 nike

我定义了以下视觉状态:

<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="EditStates">

<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:2"/>
</VisualStateGroup.Transitions>

<VisualState Name="Editing" />
<VisualState Name="Normal">
<Storyboard>
<ThicknessAnimation Storyboard.TargetName="ViewBorder" Storyboard.TargetProperty="Margin" To="0" Duration="0"/>
<DoubleAnimation Storyboard.TargetName="Header" Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(ScaleTransform.ScaleY)" To="0" Duration="0"/>
<ColorAnimation Storyboard.TargetName="EditBorder" Storyboard.TargetProperty="Background.Color" To="Red" Duration="0"/>
</Storyboard>
</VisualState>

</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
DoubleAnimationColorAnimation工作正常,使用 VisualStateManager为他们生成超过 2 秒的过渡动画。

然而, ThicknessAnimation没有动画。相反,它会在过渡期结束时捕捉到完成值。

有什么办法可以拿到 VisualStateManager为其生成过渡,还是我将被迫提供手动过渡?

最佳答案

我分析了问题,火了.NET Reflector并发现 VisualStateManager仅支持以下动画:

  • 彩色动画
  • 双动画
  • 点动画

  • 这有点糟糕,因为它没有记录在任何地方。

    为了证明它无法生成动画,请查看 VisualStageManager.GenerateToAnimation 的反向代码方法。还有一个 VisualStageManager.GenerateFromAnimation支持相同的动画子集。
    private static Timeline GenerateToAnimation(FrameworkElement root, Timeline timeline, IEasingFunction easingFunction, bool isEntering)
    {
    Timeline destination = null;

    if (destination == null)
    {
    var targetColor = GetTargetColor(timeline, isEntering);
    if (targetColor.HasValue)
    destination = new ColorAnimation { To = targetColor, EasingFunction = easingFunction };
    }

    if (destination == null)
    {
    var targetDouble = GetTargetDouble(timeline, isEntering);
    if (targetDouble.HasValue)
    destination = new DoubleAnimation { To = targetDouble, EasingFunction = easingFunction };

    }

    if (destination == null)
    {
    var targetPoint = GetTargetPoint(timeline, isEntering);
    if (targetPoint.HasValue)
    destination = new PointAnimation { To = targetPoint, EasingFunction = easingFunction };
    }

    if (destination != null)
    CopyStoryboardTargetProperties(root, timeline, destination);

    return destination;
    }

    底线...您只能在 VisualStageManager 中使用 Color、Double 或 Point 动画。如果您需要其他东西,请恢复到老式触发器...

    关于wpf - VisualStateManager 无法为 ThicknessAnimations 生成过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12744989/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com