title: (wpf) Application.Current.Resources vs FindResource
body: <p>So, I'm making a GUI thingy with WPF in C#. It looks like this:</p>
  
  <p><img src="https://i.imgur.com/W4f5uMz.png"/></p>
  
  <p>It's not done right now. Those 2 rows are my attempt at making a sort of data table, and they are hard-coded in the XAML.</p>
  
  <p>Now, I am implementing the add new fruit button functionality in the C#.
  I have the following style in the XAML that governs what the background images of the rows should look like:</p>
  
  <pre><code>&lt;Style x:Key="stretchImage" TargetType="{x:Type Image}"&gt;
      &lt;Setter Property="VerticalAlignment" Value="Stretch"/&gt;
      &lt;Setter Property="HorizontalAlignment" Value="Stretch"/&gt;
      &lt;Setter Property="Stretch" Value="Fill"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>So, in the code, I create an image for each column, <code>col0</code>, <code>col1</code>, and <code>col2</code>, and if I use the following code,</p>
  
  <pre><code>col0.Style = (Style)Application.Current.Resources["stretchImage"];
  col1.Style = (Style)Application.Current.Resources["stretchImage"];
  col2.Style = (Style)Application.Current.Resources["stretchImage"];
  </code></pre>
  
  <p>it adds a new row that looks like this:</p>
  
  <p><img src="https://i.imgur.com/if1NvZQ.png"/></p>
  
  <p>As you can see, it's not quite right...
  And stretching the window exacerbates the problem:</p>
  
  <p><img src="https://i.imgur.com/6AfTEnX.png"/></p>
  
  <p>It seems to not be respecting the style's "Stretch" property.</p>
  
  <p>But then, if I instead change my style loading code to</p>
  
  <pre><code>col0.Style = (Style)FindResource("stretchImage");
  col1.Style = (Style)FindResource("stretchImage");
  col2.Style = (Style)FindResource("stretchImage");
  </code></pre>
  
  <p>It works beautifully:</p>
  
  <p><img src="https://i.imgur.com/NwI9aFo.png"/></p>
  
  <p>(Again, the app isn't finished, so don't worry about that), but my main question is: What's the difference between <code>Application.Current.Resources[]</code> and <code>FindResource()</code>? Why does one seem to ignore some of the properties while the other doesn't? And how, if at all possible, might I get <code>Application.Current.Resources[]</code> to work properly?</p>