Pregunta

estoy mandando un lienzo que tengo con un PolyLineSegment en forma de diamante en un PathGeometry. Estoy tratando de animar la PointCollection de ella sin embargo, y parece que no puede resolver el TargetProperty. Esta es la única otra referencia a todos Google encontró que es más o menos lo que estoy tratando de hacer, y el mismo PropertyPath: http://forums.silverlight.net/forums/p/22239/78225.aspx

¿Es posible incluso obtener un Point de un PointCollection con el fin de cambiar su valor en una animación?

¿Fue útil?

Solución

Por desgracia, no creo que es posible animar los Polyline.Points ...

Esos puntos del objeto son de "System.Windows.Point" y el problema es que sus propiedades de "Y" "X" y no son propiedades de dependencia. Desafortunadamente, no hay manera de animar una propiedad que no es una propiedad de dependencia con un DoubleAnimation.

En el ejemplo que proporciona la animación se basa en Segmento PathFigure (que tienen propiedades de dependencia) y no un System.Windows.Point.

Me gustaría tratar de evitar el uso de la PolyLineSegement en su camino si desea animar a los.

Otros consejos

Se puede animar el punto de recogida de esta manera:

      <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>

(anima algunas linepoints - ve mal, pero ilustra el punto: o)

Y si desea calcular los puntos y obtener más sueave etc se puede llenar en código:

  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)) });
  }

Dibuja un cuadro que cambia de tamaño -. Se podría añadir puntos a él y conseguir el efecto deseado, más o menos

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top