WPF Buttons automatically grouped in a stackpanel

Asked

Viewed 102 times

1

I have the following little problem: I’m creating buttons from the results I find in the data bank. I would just like to position you both accordingly, and when He gets to the end, breaks the line and continues.. I am working on a bar screen, where there are tables. So I would like a help there.

private void geraBotoes() { const string strCmd = "SELECT codi_mesa_control, iden_mesa_control FROM titanium.gourmet_mesa_controle" + "WHERE stat_mesa_control is not null AND stat_mesa_control = '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);
        }
    }

1 answer

2


If I understand correctly what you probably want is to use a WrapPanel with the property Orientation="Vertical" instead of a StackPanel, so each added control will appear one below the other and when you reach the end the next turn up

  • Yes Leandro asked for the answer! I was able to solve my problem. I used Uniformgrid.I did not define sizes for him or buttons, which in case he automatically readjusts to the screen, creating asism, columns and Lines and add the buttons inside. vlw!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.