5

我定义了以下视觉状态:

<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工作正常,为它们生成超过 2 秒的VisualStateManager过渡动画。

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

有什么方法可以VisualStateManager为其生成转换,还是我将被迫提供手动转换?

4

2 回答 2

3

我分析了问题并启动了.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 动画。如果您需要其他东西,请恢复为老式触发器......

于 2014-08-07T11:59:03.630 回答
0

也许您的 ThicknessAnimation 语句不完整,我从 MSDN 的主题“ThicknessAnimation 类”中搜索流动代码示例。

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

希望这可以帮助你...

于 2012-10-05T14:29:17.863 回答