c# - Changing bitmap image dynamically -


i'm having issues of having bitmap image change dynamically between usercontrol , page load.

i'm using dispatcher timer keep image changed. not work. error stated urisource null.

i'm using ms visual studio 2012, metro application c#

code in usercontrol xaml:

    <image x:name="img">         <image.source>             <bitmapimage urisource="{binding path=bitmapimage}" />         </image.source>     </image> 

code in usercontrol:

        public bitmapimage bitmapimage         {              { return _bitmapimage; }             set             {                 if (_bitmapimage == value) return;                 _bitmapimage = value;                  raisepropertychanged("bitmapimage");             }          }      public event propertychangedeventhandler propertychanged;      private void raisepropertychanged(string propertyname)     {         if (propertychanged != null)         {             propertychanged(this, new propertychangedeventargs(propertyname));         }     } 

codes in page load:

    int eyesstate = 1;      private void minionanimation_tick(object sender, object e)     {       if (eyesstate == -1)         {              ghosts[0]._bitmapimage.urisource = new uri(this.baseuri, @"assets/test.png");         }         else         {             ghosts[0]._bitmapimage.urisource = new uri(this.baseuri, @"assets/test2.png");         }          eyesstate *= -1;     } 

try:

xaml:

<bitmapimage urisource="{binding path=bitmapimageuri}" /> 

code:

private uri _bitmapimageuri; public uri bitmapimageuri {     { return _bitmapimageuri; }     set     {         if (_bitmapimageuri == value) return;         _bitmapimageuri= value;         raisepropertychanged("bitmapimageuri");     } } 

in timer:

ghosts[0].bitmapimageuri = new uri(this.baseuri, @"assets/test.png"); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -