title: Change WPF button background image programmatically
body: <p>I'm trying to create a <code>&lt;Button/&gt;</code> with a png image for the background AND a background color.</p>
  
  <p><strong>Note:</strong> The <em>png image</em> source may not yet be known, so I can't just put them in the template.</p>
  
  <p>I've got a <code>Style</code> that looks like this:</p>
  
  <pre><code>&lt;Style x:Key="MyButton" TargetType="Button"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="Button"&gt;
                  &lt;Border CornerRadius="0"&gt;
                      &lt;Image Margin="0" Source="/MyApp;component/Images/my-image.png" Stretch="None" /&gt;
                      &lt;Border.Style&gt;
                          &lt;Style TargetType="{x:Type Border}"&gt;
                              &lt;Setter Property="Background" Value="LimeGreen" /&gt;
                          &lt;/Style&gt;
                      &lt;/Border.Style&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>which gives me a button with a png image on top of a solid LimeGreen background.</p>
  
  <p>My <code>MainWindow.xaml</code> looks somewhat like this:</p>
  
  <pre><code>&lt;Button Style="{StaticResource MyButton}" Click="btnMine_Click" /* some other props */ /&gt;
  </code></pre>
  
  <p>and the code behind it is like this:</p>
  
  <pre><code>private void btnMine_Click(object sender, RoutedEventArgs e)
  {
      // TODO: change the image src on this button
      var myButton = sender as Button;
  
      // This won't work:
      // myButton.Border.Image.Source = getNewImageString();
  }
  </code></pre>
  
  <p><strong>How do I change the image source from <code>/MyApp2;component/Images/my-image.png</code> to something else?</strong></p>