title: WPF Dynamically Generated TreeView with Checkboxes Not Displaying
body: <p>I am attempting to create a dynamically generated TreeView in a WPF project using MVVM. I have created a HierarchicalDataTemplate and a CheckableItem model that it will bind to. I have a CheckableItem type property on my ViewModel that I populate when the ViewModel is constructed. I then have the XAML use the template to create the TreeView, but nothing is displaying. I need the TreeView to contain Checkboxes and if I higher-level checkbox is checked, it should check all the lower-level ones. It should look something like this:</p>
  
  <h1><a href="https://i.stack.imgur.com/IF81n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IF81n.png" alt="Example TreeView"></a></h1>
  
  <p>I am not sure what is wrong that is causing it not to display.</p>
  
  <p><strong>ChekableItem class:</strong></p>
  
  <pre><code>public class CheckableItem
      {
          public event PropertyChangedEventHandler PropertyChanged;
          private string _name;
          public string Name
          {
              get { return _name; }
              set 
              { 
                  _name = value;
                  OnPropertyChanged("Name");
              }
          }
          public ObservableCollection&lt;CheckableItem&gt; Children { get; set; }
          private Visibility _isChecked;
          public Visibility IsChecked
          {
              get { return _isChecked; }
              set
              {
                  _isChecked = value;
                  OnPropertyChanged("IsChecked");
                  CheckChildren(value);               
              }
          }
          protected void OnPropertyChanged(string propertyName)
          {
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
          }
          private void CheckChildren(Visibility parentIsChecked)
          {
              foreach (CheckableItem child in Children)
              {
                  child.IsChecked = parentIsChecked;
              }
          }
  </code></pre>
  
  <p><strong>ViewModel:</strong></p>
  
  <pre><code>    private CheckableItem miscellaneousImports;
      public CheckableItem MiscellaneousImports
      {
          get { return miscellaneousImports; }
          set
          {
              miscellaneousImports = value;
              OnPropertyChanged("MiscellaneousImports");
          }
      }
      private void LoadCheckableItems()
              {
                  miscellaneousImports = new CheckableItem()
                  {
                      Name = "Miscellaneous Imports"
                  };
                  miscellaneousImports.Children = new ObservableCollection&lt;CheckableItem&gt;();
                  miscellaneousImports.Children.Add(new CheckableItem()
                  {
                      Name = "GPO Import"
                  });
              }
       protected void OnPropertyChanged(string propertyName)
              {
                  PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
              }
  </code></pre>
  
  <p><strong>View XAML:</strong></p>
  
  <pre><code>    &lt;Window x:Class="CAVA_IAS.Views.CaImportView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:models="clr-namespace:CAVA_IAS.Models"
          mc:Ignorable="d"
          Title="CaImportView" SizeToContent="WidthAndHeight"&gt;
      &lt;Window.Resources&gt;
          &lt;HierarchicalDataTemplate DataType="{x:Type models:CheckableItem}" ItemsSource="{Binding 
              Children}"&gt;
              &lt;StackPanel Orientation="Horizontal"&gt;
                  &lt;CheckBox IsChecked="{Binding IsChecked}"/&gt;
                  &lt;TextBlock Text="{Binding Name}"/&gt;
              &lt;/StackPanel&gt;
          &lt;/HierarchicalDataTemplate&gt;
      &lt;/Window.Resources&gt;
  
      &lt;StackPanel&gt;
          &lt;Label Content="Miscellaneous Imports" HorizontalAlignment="Center" /&gt;
          &lt;ScrollViewer&gt;
              &lt;TreeView ItemsSource="{Binding MiscellaneousImports, Mode=TwoWay, 
                    UpdateSourceTrigger=PropertyChanged}" FontSize="10" Height="450"/&gt;
          &lt;/ScrollViewer&gt;
      &lt;/StackPanel&gt;
  </code></pre>