title: HierarchicalDataTemplate with Treeview in MVVM
body: <p>I'm relatively new to MVVM and WPF. I'm attempting to fill a TreeView control with a directory and it's files / subdirectories (in effect the contents of a zip file that I have unpacked)</p>
  
  <p>Following along after this SO <a href="https://stackoverflow.com/questions/6415037/populate-treeview-from-list-of-file-paths-in-wpf">question</a>, I have the following class:</p>
  
  <pre><code>namespace IFR_Full.Model
  {
      public class Item
      {
          public string Name { get; set; }
          public string Path { get; set; }
      }
  
      public class FileItem : Item
      {
      }
  
      public class DirectoryItem : Item
      {
          public List&lt;Item&gt; Items { get; set; }
  
          public DirectoryItem()
          {
              Items = new List&lt;Item&gt;();
          }
      }
  
      public class TVItemProvider
      {
          public List&lt;Item&gt; GetItems(string path)
          {
              var items = new List&lt;Item&gt;();
              var dirInfo = new DirectoryInfo(path);
  
              foreach (var directory in dirInfo.GetDirectories())
              {
                  var item = new DirectoryItem
                      {
                          Name = directory.Name,
                          Path = directory.FullName,
                          Items = GetItems(directory.FullName)
                      };
                  items.Add(item);
              }
  
              foreach (var file in dirInfo.GetFiles())
              {
                  var item = new FileItem
                  {
                      Name = file.Name,
                      Path = file.FullName
                  };
                  items.Add(item);
              }
              return items;
          }
      }
  }
  </code></pre>
  
  <p>In my ViewModel class I have these properties:</p>
  
  <pre><code>TVItemProvider TVIP = new TVItemProvider();
  
  private List&lt;Item&gt; _tvitems;
  public List&lt;Item&gt; TVItems
  {
      get { return _tvitems; }
  }
  </code></pre>
  
  <p>which is created in this method:</p>
  
  <pre><code>private void LoadIDMLTreeView(string path)
  {
      _tvitems = TVIP.GetItems(path);
  }
  </code></pre>
  
  <p>I set the header and DataContext of my MainWindow like this:</p>
  
  <pre><code>...
  xmlns:ViewModel="clr-namespace:IFR_Full"
  xmlns:Model ="clr-namespace:IFR_Full.Model"
  ...
  
  &lt;Window.DataContext&gt;
      &lt;ViewModel:ExcelImportViewModel/&gt;
  &lt;/Window.DataContext&gt;
  </code></pre>
  
  <p>and set my treeview xaml code like this:</p>
  
  <pre><code>&lt;TreeView ItemsSource="{Binding}" Name="IDMLView" Margin="10,171.74,10,8" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"&gt;
      &lt;TreeView.Resources&gt;
          &lt;HierarchicalDataTemplate DataType="{x:Type Model:DirectoryItem}" ItemsSource="{Binding Path=TVItems}"&gt;
              &lt;TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Path}" /&gt;                  
          &lt;/HierarchicalDataTemplate&gt; 
          &lt;DataTemplate DataType="{x:Type Model:FileItem}"&gt;
       &lt;TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Path}" /&gt;
      &lt;/DataTemplate&gt;             
   &lt;/TreeView.Resources&gt;
  &lt;/TreeView&gt;
  </code></pre>
  
  <p>When I run the program in debug mode I can see that TVItems contains the appropriate items (Directories and files), but my TreeView control is blank.  </p>
  
  <p>I imagine that the issue is with the bindings?</p>