7

私は、私が持っている CanvasPolyLineSegmentPathGeometry. ただし、その PointCollection をアニメーション化しようとしていますが、TargetProperty を解決できないようです。これは、私がやろうとしていることとほぼ同じであるとGoogleが見つけた他の唯一の参照ですPropertyPath: http://forums.silverlight.net/forums/p/22239/78225.aspx

アニメーションの値を変更するためにPointからを取得することは可能ですか?PointCollection

4

2 に答える 2

3

残念ながら、Polyline.Points をアニメーション化することはできないと思います...

これらのポイント オブジェクトは「System.Windows.Point」からのものであり、問​​題はそれらの「X」および「Y」プロパティが依存プロパティではないことです。残念ながら、DoubleAnimation を使用して依存関係プロパティではないプロパティをアニメーション化する方法はありません。

あなたが提供した例では、アニメーションは System.Windows.Point ではなく PathFigure セグメント (依存関係プロパティを持つ) に基づいています。

それらをアニメーション化する場合は、パスで PolyLineSegement を使用しないようにします。

于 2011-01-06T13:57:14.533 に答える
2

次のようにポイント コレクションをアニメーション化できます。

      <Canvas Background="Tan" Width="100" Height="300" Margin="5,0,0,0">
        <Path Stroke="RosyBrown" StrokeThickness="4" >
          <Path.Data>
            <PathGeometry>
              <PathGeometry.Figures>
                <PathFigure StartPoint="5,50">
                  <PolyLineSegment x:Name="PLS" ></PolyLineSegment>
                </PathFigure>
              </PathGeometry.Figures>
            </PathGeometry>
          </Path.Data>
        </Path>
        <Canvas.Triggers>
          <EventTrigger RoutedEvent="Canvas.Loaded" >
            <BeginStoryboard>
              <Storyboard x:Name="sbPathUpDown" BeginTime="0:0:0">
                <ObjectAnimationUsingKeyFrames x:Name="objAni"
                                  Duration="0:0:2"
                                 AutoReverse="True"  RepeatBehavior="Forever"
                                  Storyboard.TargetName="PLS"
                                  Storyboard.TargetProperty="Points"  >
                  <DiscreteObjectKeyFrame Value="10,50 90,50" KeyTime="0:0:0.05"></DiscreteObjectKeyFrame>
                  <DiscreteObjectKeyFrame Value="10,60 90,50" KeyTime="0:0:0.5"></DiscreteObjectKeyFrame>
                  <DiscreteObjectKeyFrame Value="10,70 105,50" KeyTime="0:0:0.9"></DiscreteObjectKeyFrame>
                  <DiscreteObjectKeyFrame Value="10,60 100,40" KeyTime="0:0:1.2"></DiscreteObjectKeyFrame>
                  <DiscreteObjectKeyFrame Value="10,50 100,50" KeyTime="0:0:1.5"></DiscreteObjectKeyFrame>
                  <DiscreteObjectKeyFrame Value="10,60 90,50" KeyTime="0:0:1.7" ></DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger>
        </Canvas.Triggers>
      </Canvas>

(いくつかの線分をアニメーション化します - 見栄えは悪いですが、ポイントを示しています:o)

ポイントを計算してより滑らかにしたい場合は、コードで埋めることができます。

  objAni.KeyFrames.Clear();
  double offsetx = 10.0; double offsety = 50;
  double w = 40; double h = 40;
  for (int i = 0; i < 20; i++)
  {
    var scale = i * 0.1;
    var ww = w * scale;
    var hh = h * scale;
    var pts = new PointCollection();
    pts.Add(new Point(offsetx, offsety));
    pts.Add(new Point(offsetx + ww, offsety));
    pts.Add(new Point(offsetx + ww, offsety + hh));
    pts.Add(new Point(offsetx, offsety + hh));
    pts.Add(new Point(offsetx, offsety));

    objAni.KeyFrames.Add(new DiscreteObjectKeyFrame { Value = pts, KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i / 10.0)) });
  }

サイズが変化するボックスを描画します。任意のポイントを追加して、多かれ少なかれ必要な効果を得ることができます。

于 2011-01-12T22:50:04.247 に答える