title: In WPF, how to add an element to a panel in code-behind, and put it before the last existing element?
body: <p>I have a <code>StackPanel</code> and I dynamically add images to it. The <code>StackPanel</code> has a <code>Button</code> at the bottom, and I want the images to be <strong>above</strong> the <code>Button</code>. </p>
  
  <p><strong>How it works currently:</strong></p>
  
  <pre><code>&lt;StackPanel&gt;
      &lt;Button /&gt;
  
      &lt;!-- Images are added here --&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p><strong>How I want it to work:</strong></p>
  
  <pre><code>&lt;StackPanel&gt;
      &lt;!-- Images are added here --&gt;
  
      &lt;Button /&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>How can I achieve that?</p>
  
  <p>Thanks.</p>