I am beginner in c# and this is my first program in which I am trying to add data in tree and display it when click on a button
This is the code of button that add data in treeview and display it
   public MainWindow()
    {
        InitializeComponent();
    }
    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        var subModules = new List<ITreeNode>
    {
        new SubModule { Name = "Sub Module 1" }
    };
        var subThreads = new List<ITreeNode>
    {
        new SubThread { Name = "Sub Thread 1" }
    };
        var nodes = new List<ITreeNode>
    {
        new Thread { Name = "Thread ", ChildNodes = subThreads },
        new Module { Name = "Module ", ChildNodes = subModules }
    };
        var runprocesses = new List<RunProcesses>
    {
        new RunProcesses{ Name = "Process1", ChildNodes = nodes }
    };
         TreeView.ItemsSource = RunProcesses;
    }
This is xmal code
<TreeView x:Name="TreeView">
   ` <Button Content="Button" VerticalAlignment="Top" 
     Width="75"Click="Button_Click_1"/>
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type local:RunProcesses}" 
        ItemsSource="{Binding ChildNodes}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Name, StringFormat='{}{0} '}"/>
                <TextBlock Text="{Binding Path=ID, StringFormat=(ID: {0})}" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type local:Module}" ItemsSource="{Binding ChildNodes}">
            <TextBlock Text="{Binding Path=Name}" />
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type local:Thread}" ItemsSource="{Binding ChildNodes}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Name, StringFormat='{}{0} '}" />
                <TextBlock Text="{Binding Path=ID, StringFormat=(ID: {0})}" />
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type local:SubThread}" ItemsSource="{Binding ChildNodes}">
            <TextBlock Text="{Binding Path=Name}" />
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>
This code compile and run properly but when I click on button system throws an exception
System.invalidoperationexception: 'items collection must be empty before using itemssource.'
I put much efforts in identifying reason of exception but unsuccessful
Kindly guide me where I am wrong   
