WPF Buttons grouped automatically on a stackpanel

1

I have the following problem: I am creating buttons from the results that I find in the database. I would just like to position them secondarily, and when he reaches the end, breaks the line and continues .. I'm working on a Bar screen, where I have tables. So I would like a help there.

private void generatesBoxes ()         {             const string strCmd="SELECT codi_table_controle, iden_mesa_controle FROM titanium . gourmet_mesa_controle " +                                   "WHERE stat_table_controle is not null AND stat_table_controle = 'Open';";

        var dt = new DataTable("MesasControles");
        using (conexao)
        {
            conexao.Open();
            using (var da = new MySqlDataAdapter(strCmd, conexao))
            {
                da.Fill(dt);
            }
            conexao.Close();
        }
        var total = dt.Rows.Count;
        if (total > 0)
        {
            for (var i = 0; i < total; i++)
            {
                var numMesaControle = dt.Rows[i][0];
                var idenMesaControle = dt.Rows[i][1];
                var mesaControleButton = new Button {Tag = numMesaControle, Content = idenMesaControle, Margin = new Thickness(10,5,10,5),Height = 50, Width = 100, Name = "Mesa" + numMesaControle, Background = Brushes.DarkGreen, Foreground = Brushes.White};
                mesaControleButton.Click += MesaControleButton_Click;
                Conteiner.Children.Add(mesaControleButton);
            }
            //geraMaisBotoes(5);
        }
        else
        {
            geraMaisBotoes(10);
        }
    }
    
asked by anonymous 02.09.2014 / 15:06

1 answer

1

If I understood correctly what you probably want to do is use a WrapPanel with the Orientation="Vertical" property instead of a StackPanel , so each added control will appear one below the other and when it reaches the end the next return to top

    
02.09.2014 / 15:25