UWP C# Add Button Dynamically and Organizing On StackPanel

前端 未结 2 890
天命终不由人
天命终不由人 2020-12-22 10:47

I understand there are a few post asking about adding buttons dynamically but I could not find out how to organize them on the stackpanel. I have no issue addi

2条回答
  •  生来不讨喜
    2020-12-22 10:49

    Try this:

        
           
        
    

    If you need to have a button at the beginning, when you initialize your view do the following:

        Button b = new Button(); ;
        b.Content = "Button";
        b.Click += Button_Click;
        ButtonsUniformGrid.Children.Add(b);
    

    Then, everytime you click on it will put a new button in the grid. Let me know if you have any other questions about this :)


    As commented Uwp doesn't include UniformGrid if you don't specify it in your xaml. If you want to use it, just include this:

    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    

    and your UniformGrid will be like this:

    
    

提交回复
热议问题