9

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?

Community
  • 1
  • 1
Ganesh kudva
  • 990
  • 3
  • 13
  • 34

2 Answers2

12

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

<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding ImageSource}" />
    </Image.Source>
</Image>
Konstantin
  • 884
  • 6
  • 12
  • 2
    In the case of `ImageSource` I recommend to use `FallbackValue=null` in Binding to have smooth Designer always. `` – Nasenbaer Sep 21 '18 at 20:09
7

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)

Community
  • 1
  • 1
Raxak
  • 389
  • 3
  • 17
  • 1
    Hi @Rachhek, Thanks for the response. Looks like your answer is valid as well. But I was looking for XAML-based bindings & as such accepted Konstantin's answer above. – Ganesh kudva May 22 '16 at 23:43