magic987
magic987

Reputation: 25

dynamic image download

Can you look at the code below?

   Image img = new Image();

   BitmapImage bi = new BitmapImage();
   bi.UriSource = new Uri("OryxAntelope.jpg", UriKind.Relative);

   img.Source = bi;

   LayoutRoot.Children.Add(img);

It works fine. But after I comment last line of code(//LayoutRoot.Children.Add(img);) picture not downloads. What is the problem of this approach?

Thanks, Vitaliy

Upvotes: 1

Views: 824

Answers (2)

lhan
lhan

Reputation: 4635

Check out this article. You need to first download the image asynchronously with the WebClient control, and then you will be able to use/display it as you want. What I've done is set up a callback function, since its asynchronous, and you could put your code example in that function so that you don't try to add the image before it's finished downloading.

Hope this helps!

Upvotes: 1

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93561

The image is fetched only when it is first displayed. That is occurring after you add it to the layout (and the layout becomes visible).

What are you trying to accomplish? The example does not make it clear what the end result is.

Upvotes: 1

Related Questions