title: WPF Treeview and databinding a Directory Tree
body: <p>I'm trying to implement a Directory Tree View that also shows all the files in my MVVM project. My Folder and Files structure in the <code>Model</code> is like this:</p>
  
  <pre><code>public class UserDirectory
  {
     private ObservableCollection&lt;UserFile&gt; files;
     private ObservableCollection&lt;UserDirectory&gt; subfolders;
     private String directoryPath;
     //public getters and setters...
  }
  
  public class UserFile
  {
     private String filePath;
     private Category category; //Archive, Document, Exe, etc...
     //public getters and setters
  }
  </code></pre>
  
  <p>I'd like to show them in a TreeView, but after reading <a href="https://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode" rel="nofollow noreferrer">this very helpful Josh Smith article</a>, and various other sources, I still don't know how to work it out with <code>HierarchicalDataTemplate</code>. </p>
  
  <p><strong>Possible solution</strong></p>
  
  <p>I've figured out that maybe I have to create a specific type, like <code>Item</code>, that exists only for showing the name of the files and the directories, </p>
  
  <pre><code>public class Item
  {
      private List&lt;String&gt; directories;
      private List&lt;String&gt; files;
  }
  </code></pre>
  
  <p>but I'd like to reuse my class structure, because I need to show the <code>Category</code> data of the <code>UserFile</code>, for example.</p>
  
  <p><strong>The question</strong></p>
  
  <p>How can I show the files and the subfolders while maintening my current Data Structure?</p>
  
  <p><a href="https://imgur.com/a/WwSeO" rel="nofollow noreferrer">This is an example of what I want to reach</a> (I'm sorry but image uploading isn't working)    </p>