title: c# dynamicly adding item in listbox - Items not showing
body: <p>I'm trying to dynamicly add items (textbox and button) into a listbox.</p>
  
  <p>This is my <code>xaml</code>:</p>
  
  <pre><code>&lt;ListBox x:Name="projects_list" Height="459" Canvas.Left="20" Canvas.Top="86" Width="755"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;StackPanel Orientation="Vertical" Height="42"&gt;
  
              &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>And, in the <code>StackPanel</code> I want to have my 2 buttons.</p>
  
  <p>Inside a <code>foreach</code>, I create the buttons like this:</p>
  
  <pre><code>items.ForEach(delegate (Projects project)
  {
      Button txt = new Button(); // NAME
      txt.Height = 32;
      txt.Width = 320;
      txt.Content = project.name;
  
      Button gen_token = new Button(); 
      gen_token.Height = 26;
      gen_token.Width = 180;
      gen_token.Content = "Generate";
  
      this.projects_list.Items.Add(txt); 
      this.projects_list.Items.Add(gen_token);  
  }
  </code></pre>
  
  <p>But, When I add the elements into my <code>ListBox</code>, nothing appears.
  Even though, there is a good number of <code>StackPanel</code>s in my list.</p>
  
  <p>Any idea? 
  Thanks!</p>
  
  <p><strong>EDIT</strong> : 
  If I Had </p>
  
  <pre><code>      &lt;Button Content="{Binding}" &gt;&lt;/Button&gt;
  </code></pre>
  
  <p>Into the <code>stackPanel</code>, My buttons are showing, but not really has I want to, they are one by <code>stackpanel</code> and I want both buttons on every panel ..</p>
  
  <p><strong>EDIT 2 :</strong>
  So, I tried this :</p>
  
  <pre><code>        public List&lt;Dictionary&lt;string, Button&gt;&gt; Items { get; set; }
          ....
          Items = new List&lt;Dictionary&lt;string, Button&gt;&gt;();
          DataContext = this;
  </code></pre>
  
  <p>And later in the <code>each</code> </p>
  
  <pre><code>         Dictionary&lt;string, Button&gt; dict = new Dictionary&lt;string, Button&gt;() { { "name", txt }, { "token", gen_token } };
                  Items.Add(dict);
  </code></pre>
  
  <p>So In my xaml, I have :</p>
  
  <pre><code>            &lt;ListBox x:Name="projects_list" Height="459" Canvas.Left="20" Canvas.Top="86" Width="755" ItemsSource="{Binding Items}"  &gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Vertical" Height="42"&gt;
                          &lt;Button Content="{Binding Path=name}" &gt;&lt;/Button&gt;
                          &lt;Button Content="{Binding Path=token}" &gt;&lt;/Button&gt;
  
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
  </code></pre>
  
  <p>But still, nothing appears :(</p>