Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows-10 UWP Binding Image url to Image source in ListView

I am porting my WinRT app to UWP. My app tries to display an image, the uri for which is received from an online query.
I am binding it to Image source like this in XAML

<Image  Source="{Binding ImageSrc}" Stretch="UniformToFill" />


App cannot fetch image from this uri. It is only able to display images which are present in app container (Anything in /Assets/ folder)
The uri I receive from the online query is valid. I verified that by pasting the uri in browser. The browser is able to fetch & display the image from uri.

I read this post on Data Binding in WPF. It atleast says that the above binding would work if "ImageSrc is a string representation of a valid uri to an image". ImageSrc is valid uri in my case

Since the above thread is for WPF, I am not sure if that stands true even for UWP or not. Is there anything additional that I need to do in this case?

like image 891
Ganesh kudva Avatar asked May 18 '16 22:05

Ganesh kudva


2 Answers

I can give you one alternative. You can set the Image source from the code behind file. The Url does not directly render using the "source" property of the Image tag. You have to convert the URL to a Bitmap Image first then set the source property to that Bitmap object

Try this,

Image.Source = new BitmapImage(
new Uri("http://yourdomain.com/image.jpg", UriKind.Absolute));

as seen on the question here Programmatically set the Source of an Image (XAML)

like image 72
Raxak Avatar answered Sep 20 '22 00:09

Raxak


If you are looking for XAML-based binding here is how:

<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding ImageSource}" />
    </Image.Source>
</Image>
like image 22
Konstantin Avatar answered Sep 21 '22 00:09

Konstantin