0

私はこのコードを持っていますが、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();
    }

どこが間違っていますか?:(

4

1 に答える 1

0

どうやら単なる入力ミスのようです。

行で:

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

セカンダリのターゲット プロパティを設定しましたanimHeightが、animWidth ターゲット プロパティはまだ設定されていません。あなたがしたいかもしれません:

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

そして、なぜあなたは"(Width)"代わりにただを使うの"Width"ですか?

于 2012-05-26T17:39:11.650 に答える