VisualStateManager can't generate transitions for ThicknessAnimations

时间秒杀一切 提交于 2019-12-05 12:09:42

I analyzed the problem and fired up .NET Reflector and found that the VisualStateManager only supports the following animations:

  • ColorAnimation
  • DoubleAnimation
  • PointAnimation

It's kind of crappy, because it's not documented anywhere.

To prove that it cannot generate the animations take a look at the reversed code of the VisualStageManager.GenerateToAnimation method. There is also a VisualStageManager.GenerateFromAnimation that supports the same subset of animations.

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;
}

Bottomline... You can only use Color, Double or Point animations in the VisualStageManager. Revert to old-fashioned triggers if you need something else...

Maybe your ThicknessAnimation statement is not complete, i search the flowing code sample from MSDN in the topic "ThicknessAnimation Class".

<ThicknessAnimation
                  Storyboard.TargetProperty="BorderThickness"
                  Duration="0:0:1.5" FillBehavior="HoldEnd" From="1,1,1,1" To="28,14,28,14" />

Hope this could help you...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!