c# - Display loading while Caching image from URL -


i have code in wpf c# use load images web such:

if (myimgurl != "") {     var imgbitmap = new bitmapimage();     imgbitmap.begininit();     imgbitmap.urisource = new uri(myimgurl, urikind.relativeorabsolute);     imgbitmap.cacheoption = bitmapcacheoption.onload;     imgbitmap.endinit();     myimgcontrol.source = imgbitmap; } 

it works takes while before images displayed (if internet slow , all). how can have progressring (from mahapps.metro toolkit) display , enabled while image loads , disappear when image displayed?

i not aware of event trigger when image being downloaded , when loaded.

take @ following events in class bitmapsource (the base class of bitmapimage):


and note. creating bitmapimage uri , showing immediately. hence there no need set bitmapcacheoption.onload (which afaik necessary if load stream should closed after endinit). shorten code this:

if (!string.isnullorempty(myimgurl)) {     var imgbitmap = new bitmapimage(new uri(myimgurl));     myimgcontrol.source = imgbitmap;      if (imgbitmap.isdownloading)     {         // start download animation here          imgbitmap.downloadcompleted += (o, e) =>         {             // stop download animation here         };          imgbitmap.downloadfailed += (o, e) =>         {             // stop download animation here         };     } 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -