C# WPF image load like progressbar -


i'v progressbar , image. when progress bar value 50, image loaded 50%. tried add image progressbar foreground, have green shade. ugly.

how can this?

to run sample, need snake image can http://res.freestockphotos.biz/pictures/16/16242-illustration-of-a-green-snake-pv.png. have used url directly, should download image first , use it.

  1. you need control template progressbar because want show percentage status too.
  2. otherwise normal progressbar do.

code can used :

<window x:class="wpfcontroltemplates._32794074.win32794074"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="win32794074" height="600" width="1000">      <grid>         <grid.rowdefinitions>             <rowdefinition height="397*"/>             <rowdefinition height="173*"/>         </grid.rowdefinitions>         <progressbar x:name="pbarcustom" width="958" height="200"  maximum="958"  value="958" foreground="#ffe6e61f" margin="17,185,17,11.932" valuechanged="pbarcustom_valuechanged">             <progressbar.background>                 <imagebrush imagesource="http://res.freestockphotos.biz/pictures/16/16242-illustration-of-a-green-snake-pv.png"/>             </progressbar.background>             <progressbar.template>                 <controltemplate>                     <grid background="{templatebinding background}">                         <rectangle x:name="thumb" horizontalalignment="left" fill="#ffc5ea1f" stroke="#ff0db442" width="{templatebinding width}" />                          <ellipse fill="#ff7deede" height="124"  stroke="#ff0db442" width="150" verticalalignment="center" horizontalalignment="center" opacity="0.3"/>                         <label x:name="tbstatus" verticalcontentalignment="center" horizontalcontentalignment="center" fontweight="bold" fontsize="75" foreground="#ff21bd76" content="0"  />                      </grid>                 </controltemplate>             </progressbar.template>          </progressbar>         <button x:name="btnloadsnake" content="load snake" horizontalalignment="left" margin="462,14.068,0,0" verticalalignment="top" width="75" click="btnloadsnake_click" grid.row="1"/>     </grid> </window>  using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.shapes; using system.windows.threading;  namespace wpfcontroltemplates._32794074 {     /// <summary>     /// interaction logic win32794074.xaml     /// </summary>     public partial class win32794074 : window     {         public win32794074()         {             initializecomponent();          }          dispatchertimer timer;         private void btnloadsnake_click(object sender, routedeventargs e)         {             btnloadsnake.isenabled = false;             pbarcustom.value = pbarcustom.maximum;             rectangle thumb = (rectangle)pbarcustom.template.findname("thumb", pbarcustom);             thumb.width = pbarcustom.value;              label status = (label)pbarcustom.template.findname("tbstatus", pbarcustom);             status.content = ((int)(100 - ((100 * pbarcustom.value) / pbarcustom.maximum))).tostring();              dispatcher disp = pbarcustom.dispatcher;              eventhandler pbarcallbackhandler = new eventhandler(pbarcallback);              timer = new dispatchertimer(timespan.fromseconds(0.5), dispatcherpriority.normal, pbarcallback, disp);                      }          private void pbarcallback(object sender, eventargs e)         {             pbarcustom.value -= 13;             rectangle thumb = (rectangle)pbarcustom.template.findname("thumb", pbarcustom);             thumb.width = pbarcustom.value;              label status = (label)pbarcustom.template.findname("tbstatus", pbarcustom);             status.content = ((int)(100 - ((100 * pbarcustom.value) / pbarcustom.maximum))).tostring();              if (pbarcustom.value == 0)                 timer.stop();         }          private void pbarcustom_valuechanged(object sender, routedpropertychangedeventargs<double> e)         {                         if(e.newvalue == 0)                 btnloadsnake.isenabled = true;         }     } } 

Comments