I'm trying to learn C# again and I was wondering what is the approach to achieve the result I needed, this is my code, it creates the label and button when I click a button.
private void button_Copy_Click(object sender, RoutedEventArgs e)
{
counter++;
Label lbl = new Label();
lbl.Content = counter.ToString();
lbl.HorizontalAlignment = HorizontalAlignment.Center;
lbl.VerticalAlignment = VerticalAlignment.Center;
lbl.FontSize = 50;
Button bt = new Button();
bt.Content = "X";
bt.HorizontalAlignment = HorizontalAlignment.Right;
bt.VerticalAlignment = VerticalAlignment.Top;
grid.Children.Add(lbl);
grid.Children.Add(bt);
}
However I'm having a problem determining where to put the click event since it was created dynamically. What I wanted to happen was when I click the X button, it will remove the specific label and x button I clicked. So if I clicked the main button twice, it would show a 1 with an x on the top left and a 2 with an x on the top left and when I click the 2's x, it will remove both the label with 2 and the x button for 2.