Looks like you need to provide absolute URI for your images in the pics
list, using either ms-appx:/// or ms-appdata:/// and use UriKind.Absolute
instead of UriKind.Relative
in the Uri constructor.
See this MSDN article for details
Domanda
I am using the below code for generating random image from a bank of images in my assets folder of windows phone 8.1 app but it is throwing an exception though I have used the code in windows phone 8 app it worked perfectly. What is wrong with the code though I have copied it from here
List<string> pics = new List<string>()
{
"Assets/img1.png",
"Assets/img2.png",
"Assets/img3.png",
"Assets/zwp1.png",
"Assets/zwp2.png",
"Assets/zwp3.png",
"Assets/zwp4.png",
"Assets/zwp5.png"
};
Random rnd=new Random();
ImageBrush brush1 = new ImageBrush();
brush1.ImageSource = new BitmapImage(new Uri(pics[rnd.Next(0,7)],UriKind.Relative));
img1.Source = brush1.ImageSource;
Error is An exception of type System.ArgumentException
occurred in mscorlib.ni.dll
but was not handled in user code
Additional information: The given System.Uri
cannot be converted into a Windows.Foundation.Uri
. Please click here for details.
Soluzione
Looks like you need to provide absolute URI for your images in the pics
list, using either ms-appx:/// or ms-appdata:/// and use UriKind.Absolute
instead of UriKind.Relative
in the Uri constructor.
See this MSDN article for details