开发者

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 开发者_JS百科line of code(//LayoutRoot.Children.Add(img);) picture not downloads. What is the problem of this approach?

Thanks, Vitaliy


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜