无法将类型为“Windows.UI.Xaml.Controls.ItemsControl”的对象强制转换为“Windows.UI.Xaml.Controls.Image”
当我点击图像时,我在这个项目控件中放置了一个事件以查看图像,但是当我这样做时,我收到此错误,我该怎么做才能修复它。 我尝试更改为项目图像但不存在。
XAML代码:
码:
private void inlineImage_Tapped(object sender, TappedRoutedEventArgs e) { Image temp = (Image)sender; if (temp.DataContext is MultimediaElement) { } else { Image ImageToGrid = (Image)sender; ImageContent myImage = new ImageContent(); myImage.ImgUri = ImageToGrid.Source.ToString(); ImageSource imgSource = ImageToGrid.Source; gridGallery.Visibility = Visibility.Visible; stckImageMenuGallery.Visibility = Visibility.Collapsed; ImageGalleryUri = (imgSource as BitmapImage).UriSource.OriginalString; imgPopup.Source = ImageToGrid.Source; } }
Tapped
路由事件绑定到ItemsControl
,而不绑定到Image
。
这导致此行失败:
Image temp = (Image)sender;
在这种情况下应该是:
ItemsControl temp = (ItemsControl)sender;
更改代码,使其与您在ItemsControl
中创建的Image
绑定。 然后第一个演员将工作。