title: Databind my Accordion control in Silverlight 4
body: <p>I have been searching all over the web trying to find an example of databinding an Accordion control.</p>
  
  <p>I have written a simple test app to try and databind, and I can get the headers to bind, but can't seem to figure out how to get the content to bind.  Could someone help me out?</p>
  
  <p>Here is my XAML:</p>
  
  <pre><code>&lt;tk:Accordion HorizontalAlignment="Left" Margin="12,12,0,0" Name="accordion1" Width="181" Height="325" Background="White" VerticalAlignment="Top"&gt;
      &lt;tk:Accordion.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel&gt;
                  &lt;TextBlock Text="{Binding MenuHeaderName}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/tk:Accordion.ItemTemplate&gt;
      &lt;tk:Accordion.ContentTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel&gt;
                  &lt;TextBlock Text="{Binding Path=MenuItems.MenuItemName}" /&gt;
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/tk:Accordion.ContentTemplate&gt;         
  &lt;/tk:Accordion&gt;
  </code></pre>
  
  <p>And here is my code behind:</p>
  
  <pre><code>public partial class MainPage : UserControl
  {
      public class MenuItem
      {
          public MenuItem(string name) { MenuItemName = name; }
          public string MenuItemName { get; set; }
      }
  
      public class MenuHeader
      {
          public MenuHeader(string name) 
          { 
              MenuItems = new List&lt;MenuItem&gt;(); 
              MenuHeaderName = name; 
          }
          public string MenuHeaderName { get; set; }
          public List&lt;MenuItem&gt; MenuItems { get; set; }
      }
  
      public MainPage()
      {
          InitializeComponent();
  
          List&lt;MenuHeader&gt; menuHeaders = new List&lt;MenuHeader&gt;();
  
          MenuHeader robots = new MenuHeader("Robots");
          robots.MenuItems.Add(new MenuItem("Robots - Item 1"));
          robots.MenuItems.Add(new MenuItem("Robots - Item 2"));
          robots.MenuItems.Add(new MenuItem("Robots - Item 3"));
          menuHeaders.Add(robots);
  
          MenuHeader pirates = new MenuHeader("Pirates");
          pirates.MenuItems.Add(new MenuItem("Pirates - Item 1"));
          pirates.MenuItems.Add(new MenuItem("Pirates - Item 2"));
          pirates.MenuItems.Add(new MenuItem("Pirates - Item 3"));
          menuHeaders.Add(pirates);
  
          accordion1.ItemsSource = menuHeaders;
      }
  }
  </code></pre>