title: C# WPF MVVM TreeViewItem ToggleButton NEVER shows up
body: <p>I have recently been working with <code>TreeView</code> to represent files on an SFTP server. The way things load, it gets directories first and adds those to the <code>TreeView</code>. Afterwards, it loops through the directories and and then populates the files.</p>
  
  <p>The Model is as follows.</p>
  
  <pre><code>public class FileData : ViewModelBase
  {
      private string _Display = "";
      public string Display
      {
          get
          {
              return _Display;
          }
          set
          {
              _Display = value;
              OnPropertyChanged(new PropertyChangedEventArgs("Display"));
          }
      }
  }
  
  public class AlbumData : ViewModelBase
  {
      public AlbumData(string albumName, List&lt;FileData&gt; albumFileList)
      {
          if (string.IsNullOrEmpty(albumName) || albumFileList == null)
          {
              return;
          }
  
          AlbumName = albumName;
          AlbumFiles = albumFileList;
      }
  
      public string AlbumName { get; set; } = "";
  
      private List&lt;FileData&gt; _AlbumFiles = new List&lt;FileData&gt;();
      public List&lt;FileData&gt; AlbumFiles
      {
          get
          {
              return _AlbumFiles;
          }
          set
          {
              _AlbumFiles = value;
              OnPropertyChanged(new PropertyChangedEventArgs("AlbumFiles"));
          }
      }
  }
  </code></pre>
  
  <p>Then in the XAML:</p>
  
  <pre><code>            &lt;TreeView x:Name="ftpFilesTreeView" ItemsSource="{Binding ServerAlbums}"&gt;
  
                  &lt;TreeView.ItemTemplate&gt;
                      &lt;HierarchicalDataTemplate ItemsSource="{Binding AlbumFiles}" DataType="{x:Type local:AlbumData}"&gt;
                          &lt;TextBlock Text="{Binding AlbumName}"/&gt;
                          &lt;HierarchicalDataTemplate.ItemTemplate&gt;
                              &lt;HierarchicalDataTemplate DataType="{x:Type local:FileData}"&gt;
                                  &lt;TextBlock Text="{Binding Display}"/&gt;
                              &lt;/HierarchicalDataTemplate&gt;
                          &lt;/HierarchicalDataTemplate.ItemTemplate&gt;
                      &lt;/HierarchicalDataTemplate&gt;
                  &lt;/TreeView.ItemTemplate&gt;
              &lt;/TreeView&gt;
  </code></pre>
  
  <p>Then I have my <code>ObservableCollection</code> with the data for the <code>TreeView</code>.</p>
  
  <pre><code>    private ObservableCollection&lt;AlbumData&gt; _ServerAlbums = new ObservableCollection&lt;AlbumData&gt;();
      public ObservableCollection&lt;AlbumData&gt; ServerAlbums
      {
          get { return _ServerAlbums; }
          set
          {
              _ServerAlbums = value;
              OnPropertyChanged(new PropertyChangedEventArgs("ServerAlbums"));
          }
      }
  </code></pre>
  
  <p>So, my big issue here is the <code>ToggleButton</code> is not showing up after items are getting added to the <code>TreeView</code>.</p>
  
  <p>I have tried using Blend to create a custom <code>TreeViewItem</code> and tinkering with the <code>HasItems</code> property. I think the issue is <code>HasItems</code> is not getting updated as objects are getting added to to my <code>ServerAlbums[X].AlbumFiles</code> collection.</p>
  
  <p>I was thinking I could do a gross hack and just manually set <code>HasItems</code> when stuff is added, but I feel there needs to be a more elegant solution.</p>