How to add multiple new buttons from template in a UI from C# and call on click event for a particular buttons

前端 未结 2 1459
自闭症患者
自闭症患者 2020-12-22 12:21

I am reading a database file and based on the no. of entries output from the database to my query, I want to populate the buttons. And on clicking any of these buttons, I wa

2条回答
  •  伪装坚强ぢ
    2020-12-22 13:11

    Rather than creating a ControlTemplate,just create a Style.Then the code would be like :

     Button btn = new Button
     btn.Style= (Style)FindResource("RoundBtn")
     grid.Children.Add(btn);
     btn.click += new EventHandler(btn_click);
    
     private void btn_Click(object sender, RoutedEventArgs e)
    {
     }
    

提交回复
热议问题