title: WPF fill stack panel with buttons?
body: <p>I am creating buttons during runtime, calculating the size of StackPanel and dividing with button size and then adding buttons to the StackPanel.</p>
  
  <p>Now I would like final result to look like this:</p>
  
  <pre><code>********
  **BBBB**
  **BBBB**
  **BBBB**
  ********
  </code></pre>
  
  <p>Now, with StackPanel i am getting this:</p>
  
  <pre><code>********
  **    **
  **BBBB**
  **    **
  ********
  </code></pre>
  
  <p>Is StackPanel proper control to do this kind of work?</p>
  
  <p>Code below is for another StackPanel (which works) but buttons are added verticaly:</p>
  
  <pre><code>*****
  **B**
  **B**
  **B**
  *****
  </code></pre>
  
  <p>This is in Program.cs</p>
  
  <pre><code> private void addButtonGrp()
      {
  
          //Calculate size of container to determine number of buttons
          int btnMinimumHeightSize = 30;
          int btnNumberCreated = (Convert.ToInt16(rctGrupe.Height) / btnMinimumHeightSize);  
  
          for (int i = 0; i &lt; btnNumberCreated ; i++)
          {
  
  
              CreateGroupButtons btn = new CreateGroupButtons();
              var btnX = new Button();
  
              btnX=(btn.addButton(i,btnMinimumHeightSize,Convert.ToInt16(stPanel.Width)));
              btnX.Click += ClickHandler2;
  
              if (i==btnNumberCreated -1 )
              {
                  btnX.Height = btnMinimumHeightSize + ((Convert.ToDouble(rctGrupe.Height) / btnMinimumHeightSize) % 1)*(btnNumberCreated);
              }
  
              stPanel.Children.Add(btnX);
          }
      }
  </code></pre>
  
  <p>And this is in class CreateGroupButtons</p>
  
  <pre><code>public Button addButton(int num, int btnHeight, int btnWidth)
      {
  
          var btnX = new Button { Content = "Group " + num, Tag = num, Height = btnHeight, Width=btnWidth };
          return btnX;
      }
  </code></pre>