title: Control Template used in Code Behind to add dynamically to a StackPanel
body: <p>I have the following ControlTemplate in my /Themes/Generic.xaml:</p>
  
  <pre><code>&lt;ControlTemplate x:Key="GroupList" TargetType="{x:Type Expander}"&gt;
          &lt;Expander IsExpanded="True"&gt;
              &lt;Expander.Header&gt;
                  &lt;Label Style="{DynamicResource headline3}" FontWeight="Light" BorderThickness="0 0 0 1"&gt;TEst group&lt;/Label&gt;
              &lt;/Expander.Header&gt;
              &lt;ListBox x:Name="lstBoxContacts" Height="auto" BorderThickness="0" VerticalAlignment="Top" AllowDrop="True" PreviewDragOver="lstBoxContacts_PreviewDragOver"  Drop="lstBoxContacts_Drop" ItemsSource="{Binding Contacts}"&gt;
                  &lt;ListBox.ItemTemplate&gt;
                      &lt;DataTemplate&gt;
                          &lt;Label Content="{Binding Fullname}" /&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ListBox.ItemTemplate&gt;
  
                  &lt;ListBox.ContextMenu&gt;
                      &lt;ContextMenu &gt;
                          &lt;MenuItem Header="Send Message" Command="local:CustomCommands.cmdMessageWrite"/&gt;
                          &lt;MenuItem Header="Show Details" Command="local:CustomCommands.cmdContactDetails"/&gt;
                          &lt;MenuItem Header="Delete" Command="local:CustomCommands.cmdContactDelete"/&gt;
                      &lt;/ContextMenu&gt;
                  &lt;/ListBox.ContextMenu&gt;
              &lt;/ListBox&gt;
          &lt;/Expander&gt;
      &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>This should give me an expander with a Listbox in it. To which I can pass a <code>ObservableCollection&lt;User&gt;</code> object, that is than being displayed (Only the Fullname attribute of the user).</p>
  
  <p>In my MainWindow.xaml I have a Stackpanel named "stkpContactsAndGroups" to which I would like to add Expanders programmatically and dynamically. </p>
  
  <p>The contents come from an API call (Which all works).</p>
  
  <p>From what I have seen I should work with Template.FindName. However, when I supply the origin where said template can be found VS bucks me.</p>
  
  <pre><code>Expander grp = (Expander)Template.FindName("GroupList", new Generic());
  stkpContactsAndGroups.Children.Add(grp);
  </code></pre>
  
  <p>It cannot convert Generic() to FrameworkElement. Am I missing the point here? </p>