2011-01-03 9 views
7

Sto ritagliando una tela che ho con un diamante PolyLineSegment in un PathGeometry. Sto cercando di animare il PointCollection di esso però, e non riesco a risolvere la TargetProperty. Questo è l'unico altro riferimento tutti Google ha scoperto che è più o meno quello che sto cercando di fare e lo stesso PropertyPath: http://forums.silverlight.net/forums/p/22239/78225.aspxÈ possibile animare un PolyLineSegment in Silverlight, ad esempio PointCollection?

E 'anche possibile ottenere un Point da un PointCollection al fine di modificare i suoi valori in un'animazione?

risposta

3

Purtroppo non credo che è possibile animare le Polyline.Points ...

Questi punti sono oggetto da "System.Windows.Point" e il problema è che il loro "X" e "Y "le proprietà non sono proprietà di dipendenza. Sfortunatamente non c'è modo di animare una proprietà che non sia una proprietà di dipendenza con una DoubleAnimation.

Nell'esempio che hai fornito l'animazione è basata su PathFigure Segment (che ha proprietà di dipendenza) e non su System.Windows.Point.

Vorrei provare a evitare di utilizzare PolyLineSegement nel percorso se si desidera animare quelli.

2

Si potrebbe animare il punto di raccolta in questo modo:

 <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 alcune linepoints - sembra male, ma illustra il punto: o)

E se si vuole calcolare i punti e ricevere più liscio ecc è possibile riempire in codice:

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

Disegna una scatola che cambia dimensione - si potrebbe aggiungere tutti i punti ad esso e ottenere l'effetto desiderato, più o meno.

+1

Con questo dovrebbe essere facile effettuare una modifica simile a quella della figura. Scalare e ruotare è più facile con le trasformazioni. –

Problemi correlati