Windows phone 7 Windows phone 7图像阵列

Windows phone 7 Windows phone 7图像阵列,windows-phone-7,Windows Phone 7,我有一个字符串数组 images[]={"1.png","2.png","n...png"}; 我正在尝试将图像源设置为数组中的图像 myImage.Source=images[2]; 我得到以下错误 Cannot implicitly convert type 'string' to 'System.Windows.Media.ImageSource 我在这里做错了什么?嗯,错误信息对我来说似乎很清楚。类型为ImageSource,而不是string。因此,为了分配Source属性,您需

我有一个字符串数组

images[]={"1.png","2.png","n...png"};
我正在尝试将图像源设置为数组中的图像

myImage.Source=images[2];
我得到以下错误

Cannot implicitly convert type 'string' to 'System.Windows.Media.ImageSource

我在这里做错了什么?

嗯,错误信息对我来说似乎很清楚。类型为
ImageSource
,而不是
string
。因此,为了分配
Source
属性,您需要一个
ImageSource
。例如:

myImage.Source = new BitmapImage(new Uri(images[2], UriKind.Relative));
myImage.Source = new BitmapImage(new Uri(images[2], UriKind.Relative));

ImageSource
是一个抽象类;实际上,
BitmapImage
是您通常想要使用的具体类。)

嗯,错误消息对我来说似乎相当清楚。类型为
ImageSource
,而不是
string
。因此,为了分配
Source
属性,您需要一个
ImageSource
。例如:

myImage.Source = new BitmapImage(new Uri(images[2], UriKind.Relative));
myImage.Source = new BitmapImage(new Uri(images[2], UriKind.Relative));

ImageSource
是一个抽象类;实际上,
BitmapImage
是您通常想要使用的具体类。)

在代码中,您不能设置源的字符串路径。Image.Source需要一个Media.ImageSource,这意味着您需要明确创建一个BitMapImage并分配给源


在代码中,不能设置源的字符串路径。Image.Source需要一个Media.ImageSource,这意味着您需要明确创建一个BitMapImage并分配给源