title: Access children from contextmenu control template c#
body: <p>I am trying to access a control from a control's context menu's control template.My xaml is :</p>
  
  <pre><code> &lt;Button x:Name="button1" ContextMenuService.Placement="top" Content="Button" HorizontalAlignment="Left" Margin="2,543,0,0" VerticalAlignment="Top" Width="75" Grid.ColumnSpan="2"&gt;
          &lt;Button.ContextMenu&gt;
              &lt;ContextMenu x:Name="btconmn" &gt;
                  &lt;ContextMenu.Template&gt;
                      &lt;ControlTemplate&gt;
                          &lt;Grid x:Name="newgrid"  Width="183" Height="190"&gt;
                              &lt;Rectangle Fill="#FF263349" x:Name="newfolder" HorizontalAlignment="Left" VerticalAlignment="Top" Width="179" Height="32" Margin="2,1,0,0"/&gt;
                          &lt;/Grid&gt;
                       &lt;/ControlTemplate&gt;
                  &lt;/ContextMenu.Template&gt;
              &lt;/ContextMenu&gt;
          &lt;/Button.ContextMenu&gt;
      &lt;/Button&gt;   
  </code></pre>
  
  <p>Here i'm trying to access the <code>newfolder</code> rectangle. So far i tried :</p>
  
  <pre><code> public override void OnApplyTemplate()
  {
      base.OnApplyTemplate();
      var template = btconmn.Template;
      var myControl = (Rectangle)template.FindName("newfolder", btconmn);
   }
  </code></pre>
  
  <p>which returns a null reference exception.Any help ?</p>