title: Use a user control as a DataTemplate within a WPF application
body: <p>I am trying to create a user control within a WPF application that will serve as a <code>DataTemplate</code> for a <code>ListBoxItem</code>. The user control a grid with 4 <code>TextBlock</code>s. This control also contains other shapes and images more for visual aid than anything so I am omitting them from the code in this question for clarity. </p>
  
  <p>When I drop the user control on my mainwindow.xaml I can see the control and the properly bound fields point to the first record in the datasource. What I want to do is have this control render repeatedly  within either a listbox or a wrap panel for each record within the database.</p>
  
  <p>Can anyone provide me with a pointer or sample of how to have a user control render as a <code>DataTemplate</code> within the <code>ListBox</code> control/other panel.</p>
  
  <p>Up to this point I have tried the following with no avail:
  Thanks in advance for any tips.</p>
  
  <pre><code>&lt;!--within Window.Resource --&gt;
  &lt;DataTemplate x:Key="myActivity"&gt;
          &lt;local:ucActivityItm /&gt; &lt;!--usercontrol --&gt;
  &lt;/DataTemplate&gt;
  
  &lt;!-- Listbox within the window --&gt;
  &lt;ListBox HorizontalAlignment="Stretch" ItemTemplate="{DynamicResource myActivity}"  VerticalAlignment="Stretch"&gt;
   &lt;ListBoxItem&gt;
  &lt;!-- control also added for testing to ensure it rendered out--&gt;
  &lt;local:ucActivityItm /&gt;   
  &lt;/ListBoxItem&gt;        
  &lt;/ListBox&gt;
  </code></pre>