我单击一个图像,然后通过给被单击的图像提供要显示的图像的源补丁来试图显示的另一张卡片将不显示新图像。它仅在我的网格上显示空白。到目前为止,这是我的代码
Image _imgMatch1 = new Image();
Image _imgMatch2 = new Image();
Image _imgMatch3 = new Image();
Image _imgMatch4 = new Image();
Image imagedClickedOne;
Image imagedClickedTwo;
Dictionary<string, Image> minionsDict = new Dictionary<string, Image>();
int count = 0;
public MainPage()
{
this.InitializeComponent();
_imgMatch1.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile1.jpg", UriKind.Absolute));
_imgMatch2.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile2.jpg", UriKind.Absolute));
_imgMatch3.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile3.jpg", UriKind.Absolute));
_imgMatch4.Source = new BitmapImage(new Uri("ms-appx://Assets/Tile4.gif", UriKind.Absolute));
//var imgSource = _imgMatch1;
minionsDict.Add("_imgTile1", _imgMatch1);
minionsDict.Add("_imgTile2", _imgMatch2);
minionsDict.Add("_imgTile3", _imgMatch3);
minionsDict.Add("_imgTile4", _imgMatch4);
minionsDict.Add("_imgTile5", _imgMatch1);
minionsDict.Add("_imgTile6", _imgMatch2);
minionsDict.Add("_imgTile7", _imgMatch3);
minionsDict.Add("_imgTile8", _imgMatch4);
}
private void OnClickTap(object sender, TappedRoutedEventArgs e)
{
count++;
Image imagedClicked = sender as Image;
var imageName = imagedClicked.Name;
Image image = minionsDict[imageName];
if (imagedClicked != null)
{
if (imagedClickedOne == null)
{
imagedClickedOne = image;
BitmapImage myBitmapImage = new BitmapImage
{
UriSource = new Uri("ms-appx://Assets/Tile2.jpg")
};
imagedClicked.Source = myBitmapImage;
return;
}
imagedClickedTwo = image;
if (imagedClickedOne.Name == imagedClickedTwo.Name)
{
imagedClickedOne = null;
imagedClickedTwo = null;
}
}
请注意,我正在使用网格设置我的8个正方形。我的XAML代码就是
<Image "attributes">
<Image.Source>
<BitmapImage uriSource = "source" />
<Image.Source>
<Image>
所有8张初始图像乘以8