So I have a Canvas and a set of 18 Images in it and I want to random the Images inside it
foreach (var myImg in GameCanvas.Children.OfType<Image>())
{
GetTop.Add(Canvas.GetTop(myImg));
GetLeft.Add(Canvas.GetLeft(myImg));
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 change places but some of them disappear completely and the rest change places as intended. I don't get why that happens. Any Idea?
Aucun commentaire:
Enregistrer un commentaire