【问题标题】:Silverlight "Animation target not specified."Silverlight“未指定动画目标。”
【发布时间】:2012-05-26 23:18:49
【问题描述】:

我有这段代码,但我不能使用它,因为当我调用 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();
    }

我哪里错了? :(

【问题讨论】:

    标签: silverlight animation storyboard


    【解决方案1】:

    显然这只是一个打字错误。

    在行中:

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

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

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

    为什么你使用"(Width)" 而只是"Width"

    【讨论】:

      猜你喜欢
      • 2011-10-03
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2016-09-26
      相关资源
      最近更新 更多