I am new to C# and OOP, and still trying to wrap my mind around that. Watched a lot of tutorials, and somethings i do understand, other not so much...
Anyway, I am trying to give myself problems, and then solve them.
Here is the problem.
I know how to create some control on WPF during runtime:
private void addButton()
{
for (int i = 0; i < 10; i++)
{
var btnX = new Button { Content = "btn" + i };
btnX.Click += ClickHandler1;
stPanel.Children.Add(btnX);
}
}
But, now I would like this method to exist in separated class which can be called from another class, passed some arguments, and then create buttons in the class that passed arguments.
So in my Programs.cs now I have:
private void addButtonX()
{
for (int i = 0; i < 10; i++)
{
CreateGroupButtons btn = new CreateGroupButtons();
stPanel.Children.Add(btn.addButton(i));
}
}
I have Class:
class CreateGroupButtons
{
public Button addButton(int num)
{
var btnX = new Button { Content = "btn" + num };
return btnX;
}
}
And the buttons are created, but now there is just one more problem, and i am not sure how to fix that:
How to add Handler event?
btnX.Click += ClickHandler1;
Thank you!