我正在使用带有图像的边框并更改其来源,在C#中制作记忆游戏。更改第一个源可以正常工作,但是在第二次翻转后我调用一个函数来检查它们是否匹配,然后再将它们翻转到正确或隐藏的图像。我对第二张图片一直有问题,因为我在功能退出之前尝试过的事件因此第二张图片只显示隐藏的图像。是否有一个事件我可以调用以在退出之前检查图像是否已加载?
//border mousedown event
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
//flip the image over
Border picBorder = sender as Border;
picBorder.IsEnabled = false; //disable the border so they can't click it again
int index = Int32.Parse(Regex.Match(picBorder.Name, @"\d+").Value); //get border #
BitmapImage car = new BitmapImage(carImages[index]);
picBorder.Child = new Image { Source = car};
picBorder.IsEnabled = false;
//Storing border locations for checking later
borderLocations[currentCarsFlipped] = picBorder;
currentCarsFlipped++;
}
一旦CurrentCarsFlipped == 2,我需要检查是否匹配。目前,我有checkWin()看起来会起作用,但是当你每2次点击只能看到1张图片时很难调试
答案 0 :(得分:0)
使用布尔变量 如果未更新时为False,更新后为true,则可以检查