C# 改变图像元素的来源
我尝试更改C# 改变图像元素的来源,c#,windows-phone-7,C#,Windows Phone 7,我尝试更改image1的图片。在收藏中我有“1.png”和“2.png” 在image1的属性中,Source是“/Appname;component/pictures/1.png” 我写道: image1.Source = "/Appname;component/pictures/2.png"; 当然,这不起作用,因为“不可能将字符串隐式转换为System.Windows.Media.ImageSource” 如何将image1中的图片更改为“2.png”您不能直接将字符串指定为图像源。但是
image1
的图片。在收藏中我有“1.png”和“2.png”
在image1
的属性中,Source
是“/Appname;component/pictures/1.png”
我写道:
image1.Source = "/Appname;component/pictures/2.png";
当然,这不起作用,因为“不可能将字符串隐式转换为System.Windows.Media.ImageSource”
如何将
image1
中的图片更改为“2.png”您不能直接将字符串指定为图像源。但是您可以使用位图图像
作为源
例如:
BitmapImage bitmap = new BitmapImage(new Uri("/Appname;component/pictures/2.png", UriKind.Relative));
image1.Source = bitmap;
如果这不起作用,那么您的Uri
(图像路径)有问题,您应该查看Zannjaminderson提供的链接(在评论中)。您是否查看了此问题和答案-?