コード例 #1
0
 public Storyboard Shuffle()
 {
     if (Vertices[0] is VerticeControl v && v.IsLoaded)
     {
         canvas.IsHitTestVisible = false;
         var tempV = new List <IVertice <int> >(Vertices);
         var pts   = new Point[Vertices.Count];
         var r     = new Random();
         for (int i = 0; i < pts.Length; i++)
         {
             var len = tempV.Count;
             var idx = r.Next() % len;
             if (idx == i)
             {
                 i--;
                 continue;
             }
             var vc = tempV[idx] as VerticeControl;
             pts[i] = new Point(vc.CanvasLeft, vc.CanvasTop);
             tempV.RemoveAt(idx);
         }
         var sb = new Storyboard();
         for (int i = 0; i < pts.Length; i++)
         {
             var vc = Vertices[i] as VerticeControl;
             sb.Children.Add(Anima.TranslateAnimation(pts[i], vc, Anima.NormalDuration));
         }
         //sb.Completed += (o, e) => { canvas.IsHitTestVisible = true; };
         //sb.Begin();
         return(sb);
     }
     return(null);
 }