title: WPF TreeView binding through XAML
body: <p>So I have a class structure like this</p>
  
  <pre><code>Store
      Owner
      Cashier
      List of Products
          Product Name
          Price
      List of Vendors
          Company Name
          Contact Name
  </code></pre>
  
  <p>So there are 4 objects: Store, Person (Owner and Cashier), Product and Vendor.</p>
  
  <p>I want to find a way to bind this structure into a XAML tree, so each node is represents an object of this structure like:</p>
  
  <p><a href="http://img23.imageshack.us/img23/9337/treexq.png" rel="nofollow noreferrer">image http://img23.imageshack.us/img23/9337/treexq.png</a></p>
  
  <p>Up until now, I've only been able to this with one top object -> one sub object. Like this:</p>
  
  <pre><code>Store
     - Departmen 1 Products
         Book 1
         Book 2
         Book 3
     - Department 2 Products
         Bike 1
         Bike 2
         Bike 3
  </code></pre>
  
  <p>So the important difference here is that in the first tree, the sub nodes are 3 different types of object (Store has 2 Person objects, 1 Product and 1 Vendor objects); and in the second one, each root node has only one type of sub node (Store has Department, Department has Products).</p>
  
  <p>I've done the second example using HierarchicalDataTemplates, so I thought this would solve my problem, but it doesn't. Any Idea on how I can do this? Here's the code that creates the Store structure:</p>
  
  <pre><code>public partial class Window1 : Window
  {
      public Window1()
      {
          InitializeComponent();
          this.DataContext = new List&lt;Store&gt;() { Store.CreateStore() };
      }
  }
  
  public class Store
  {
      public string StoreName { get; set; }
      public Person Owner { get; set; }
      public Person Cashier { get; set; }
      public List&lt;Product&gt; Products { get; set; }
      public List&lt;Vendor&gt; Vendors { get; set; }
  
      public Store()
      {
          this.Products = new List&lt;Product&gt;();
          this.Vendors = new List&lt;Vendor&gt;();
      }
  
      public static Store CreateStore()
      {
          Store store = new Store();
  
          // set name
          store.StoreName = "Book store";
  
          // set staff
          store.Owner = new Person() { FirstName = "John", LastName = "Smith" };
          store.Cashier = new Person() { FirstName = "Jane", LastName = "Smart" };
  
          // add products
          store.Products.Add(new Product() { Name = "Mechanical Pencil", Price = 1.25m});
          store.Products.Add(new Product() { Name = "Pen", Price = 2.50m });
          store.Products.Add(new Product() { Name = "WPF Book", Price = 28.94m });
          store.Products.Add(new Product() { Name = "ASP.NET Book", Price = 29.50m });
  
          // add vendors
          store.Vendors.Add(new Vendor() { CompanyName = "Bic", ContactName = "Bill Gates" });
          store.Vendors.Add(new Vendor() { CompanyName = "O'Reilly", ContactName = "Steve Jobs" });
  
          return store;
      }
  }
  
  public class Person
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
  }
  
  public class Product
  {
      public string Name { get; set; }
      public decimal Price { get; set; }
  }
  
  public class Vendor
  {
      public string CompanyName { get; set; }
      public string ContactName { get; set; }
  }
  </code></pre>
  
  <p>I want to avoid creating the tree structure in the code side. Any help will be GREATLY appreciated.</p>