title: Accessing a given child of a ControlTemplate programmatically
body: <p>I have this ControlTemplate that contains stuff (gradients in this case) that I want to be able to access programmatically and after hours of trial and error I feel that it's finally time to turn to you for assistance, StackOverflow.</p>
  
  <p>The template generates a flower, and I didn't know what to use, so I just picked the Thumb-element, since I've used that before in a similar manner. If you can think of anything else that would be better suited, please let me know.</p>
  
  <p>Anyways, this is the beginning of my ControlTemplate, from the XAML-file:</p>
  
  <pre class="lang-xaml prettyprint-override"><code>&lt;ControlTemplate x:Key="cherryFlowerStyle" TargetType="{x:Type Thumb}"&gt;
                          &lt;Viewbox Width="119.560" Height="114.268" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
                              &lt;Canvas Width="119.560" Height="114.268"&gt;
                                  &lt;Canvas&gt;
                                      &lt;!-- Layer 1/&lt;Path&gt; --&gt;
                                      &lt;Path Data="... (removed to save space) ..."&gt;
                                          &lt;Path.Fill&gt;
                                              &lt;RadialGradientBrush x:Name="cherryFlowerColorGradient" MappingMode="Absolute" GradientOrigin="593.380,333.416" Center="593.380,333.416" RadiusX="36.460" RadiusY="36.460"&gt;
                                                  &lt;RadialGradientBrush.GradientStops&gt;
                                                      &lt;!-- Flower color --&gt;
                                                      &lt;GradientStop x:Name="cherryFlowerColorGradientOuterColor" Offset="0.15" Color="#ffd6e062"/&gt;
  </code></pre>
  
  <p>And here's what I'm doing in C#:</p>
  
  <pre class="lang-cs prettyprint-override"><code>Thumb flower = new Thumb();
  flower.Template = TryFindResource("cherryFlowerStyle") as ControlTemplate;
  GradientStop grStop = (GradientStop)flower.Template.FindName("cherryFlowerColorGradientOuterColor", flower);
                          Console.WriteLine("gradient: " +grStop);
  </code></pre>
  
  <p>Creating a new Thumb and applying the template works (it's drawn as a flower on the canvas).
  Trying to access the gradients inside the template, however, does not work. I hope there's a good solution to this, or else I have to do it the ugly way; create a flower off-screen (in XAML) and reference that in the code-behind, because that works :/</p>
  
  <p>Thanks in advance!</p>