Silverlight“未指定动画目标”。

时间:2012-05-19 20:27:26

标签: silverlight animation storyboard

我有这个代码,但是我不能使用它,因为当我调用sb.Begin()时抛出异常:

  

未指定动画目标。

    public void TableCardAnimation(UserControl cardControl, double Height, double Width)
    {
        Storyboard sb = new Storyboard();
        DoubleAnimation animHeight = new DoubleAnimation();
        animHeight.Duration = new Duration(new TimeSpan(0, 0, 2));
        animHeight.From = cardControl.Height;
        animHeight.To = Height;
        sb.Children.Add(animHeight);
        Storyboard.SetTarget(animHeight, cardControl);
        Storyboard.SetTargetProperty(animHeight, new PropertyPath("(Height)"));


        DoubleAnimation animWidth = new DoubleAnimation();
        animWidth.Duration = new Duration(new TimeSpan(0, 0, 2));
        animWidth.From = cardControl.Width;
        animWidth.To = Width;
        sb.Children.Add(animWidth);
        Storyboard.SetTarget(animWidth, cardControl);
        Storyboard.SetTargetProperty(animHeight, new PropertyPath("(Width)"));

        sb.Begin();
    }

我哪里错了? :(

1 个答案:

答案 0 :(得分:0)

显然这只是打字错误。

在该行:

Storyboard.SetTargetProperty(animHeight, new PropertyPath("(Width)"));

您已为animHeight辅助设置目标属性,但您的animWidth目标属性仍未设置。您可能想要这样做:

Storyboard.SetTargetProperty(animWidth, new PropertyPath("(Width)"));

为什么使用"(Width)"代替"Width"