c# - change image source on click -


i've made custom image checkbox , want switch between checked , unchecked version every time image clicked. sourcecode:

xaml

<checkbox name="checkbox1" padding="0" borderthickness="0" margin="5" grid.row="1">     <image name="image1" margin="-14,0,0,0" source="checkbox0.png" mousedown="image_mousedown" stretch="uniform"/> </checkbox> 

c#

private void image_mousedown(object sender, mousebuttoneventargs e) {      if (e.leftbutton == mousebuttonstate.pressed)      {          if (checkbox1checked)          {              image1.begininit();              image1.source = new bitmapimage(new uri("/checkbox0.png", urikind.relativeorabsolute));              image1.endinit();              checkbox1checked = false;          }           if (!checkbox1checked)          {              image1.begininit();              image1.source = new bitmapimage(new uri("/checkbox1.png", urikind.relativeorabsolute));              image1.endinit();              checkbox1checked = true;          }      } } 

use uncheck , check event of checkbox, , set image source in there

<checkbox name="checkbox1" padding="0" unchecked="chkbox_unchecked" checked="chkbox_checked borderthickness="0" margin="5" grid.row="1">    <image name="image1" margin="-14,0,0,0" source="checkbox0.png" stretch="uniform"/> </checkbox>             private void chkbox_checked(object sender, routedeventargs e)         {             setimage("/checkbox0.png");         }          private void chkbox_checked(object sender, routedeventargs e)         {              setimage("/checkbox1.png");         }      private void setimage(string path)     {         image1.begininit();                 image1.source = new bitmapimage(new uri(path, urikind.relativeorabsolute));                 image1.endinit();      } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -