Canvas Image Shuffle

◇◆丶佛笑我妖孽 提交于 2020-01-06 21:06:22

问题


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?

来源:https://stackoverflow.com/questions/30312543/canvas-image-shuffle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!