Canvas Image Shuffle

2019-09-08 04:54发布

So I have a Canvas and a set of 18 Images in it and I want to shuffle the Images

foreach (var myImg in GameCanvas.Children.OfType<Image>())
{
    GetTop.Add(Canvas.GetTop(myImg));
    GetLeft.Add(Canvas.GetLeft(myImg));
    listNum++;
    myImg.IsTapEnabled = false;
}

I have this part to add the Top and Left of each image in a separate list BUT when I try this

foreach (var myImg in GameCanvas.Children.OfType<Image>())
        {           
            int ran = rand.Next(GetTop.Count);
            double Top = GetTop[ran];
            double Left = GetLeft[ran];
            Canvas.SetTop(myImg, Top);
            Canvas.SetLeft(myImg, Left);
            GetTop.Remove(Top);
            GetLeft.Remove(Left);
        }

the Images don't change places one box with another as intended. Some Images are lost and it doesn't Show them. Any Idea?

0条回答
登录 后发表回答