无法将“Windows.UI.Xaml.Controls.ItemsControl"类型的对象转换为“Windows.UI.Xaml.Controls.Image" [英] Unable to cast object of type 'Windows.UI.Xaml.Controls.ItemsControl' to type 'Windows.UI.Xaml.Controls.Image'
本文介绍了无法将“Windows.UI.Xaml.Controls.ItemsControl"类型的对象转换为“Windows.UI.Xaml.Controls.Image"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击图像时,我在此项目控件中放置了一个点击事件以查看图像,但是当我这样做时,我收到了这个错误,我该怎么做才能修复它.我尝试更改为项目图像但不存在.
I put a event of tapped in this Item Control to see the image when I tap the image, but when I do I receive this error what I to do to fix it. I try to change to Item Image but didn't exist.
XAML 代码:
<ItemsControl x:Name="icPareoExerciseControl1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ItemsSource="{Binding lstPareoItem}"
ItemTemplate="{StaticResource ExercisePareoDataTemplate2}"
Foreground="Black" Width="400"
Margin="100,0,0,0"
Tapped="inlineImage_Tapped"/>
代码:
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
代码>.
The Tapped
routed event is bound to the ItemsControl
, not to the Image
.
这导致此行失败:
Image temp = (Image)sender;
在这种情况下应该是:
ItemsControl temp = (ItemsControl)sender;
更改您的代码,使其绑定到您在 ItemsControl
中创建的 Image
.然后第一个演员将起作用.
Alter your code so it binds to the Image
you are creating in your ItemsControl
. Then the first cast will work.
这篇关于无法将“Windows.UI.Xaml.Controls.ItemsControl"类型的对象转换为“Windows.UI.Xaml.Controls.Image"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文