title: change image source on click
body: <p>I've made a custom image for a checkbox and want it to switch between the checked and the unchecked version every time the image is clicked. My sourcecode:</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;CheckBox Name="checkBox1" Padding="0" BorderThickness="0" Margin="5" Grid.Row="1"&gt;
      &lt;Image Name="image1" Margin="-14,0,0,0" Source="checkbox0.png" MouseDown="Image_MouseDown" Stretch="Uniform"/&gt;
  &lt;/CheckBox&gt;
  </code></pre>
  
  <p><strong>C#</strong></p>
  
  <pre><code>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;
           }
       }
  }
  </code></pre>