Click here to Skip to main content
15,877,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
xaml code
<listview name="AddonListView"> Grid.Row="1"
<listview.itemtemplate> <datatemplate>
<Image Margin="10"
Source="{Binding AddonImagepath}" />

c# code
Image addon = new Image();
addon.Name = "PART_Addon_" + System.DateTime.Now;
addon.SetValue(Canvas.TopProperty, 0);
addon.SetValue(Canvas.LeftProperty, 0);
addon.SetValue(Canvas.ZIndexProperty, 0);
addon.Stretch = Stretch.Uniform;
var bitmap = new BitmapImage(new Uri(imagePath)) ;

i am getting error

Invalid URI: The format of the URI could not be determined.
Sergey Alexandrovich Kryukov 21-Nov-13 1:31am    
And what is the example of this URI? What is the ImagePath value?

1 solution

You need to look at the value in imagePath - it should contain a valid absolute URI.
If you look at MSDN: Constructor: URI(string)[^] it lists all the reasons it can throw the exception:
uriString is empty.
The scheme specified in uriString is not correctly formed. See CheckSchemeName.
uriString contains too many slashes.
The password specified in uriString is not valid.
The host name specified in uriString is not valid.
The file name specified in uriString is not valid.
The user name specified in uriString is not valid.
The host or authority name specified in uriString cannot be terminated by backslashes.
The port number specified in uriString is not valid or cannot be parsed.
The length of uriString exceeds 65519 characters.
The length of the scheme specified in uriString exceeds 1023 characters.
There is an invalid character sequence in uriString.
The MS-DOS path specified in uriString must start with c:\\.

Without access to the variable content, we can't tell you which is causing the problem. Either use the debugger to put a breakpoint on the line:
var bitmap = new BitmapImage(new Uri(imagePath)) ;
And manually examine the content, or log the content to a file before you execute the line and look at it later.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900