0

I have

List<Canvas> cv = new List<Canvas>();
List<Button> btn = new List<Button>();

But I cannot do this:

cv.Add(btn);

How do I add list of Button to a list of Canvas?

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
KMC
  • 19,548
  • 58
  • 164
  • 253

2 Answers2

1

You cannot add a list of buttons to a list of canvases, since a list of buttons is not a canvas.

Had that been possible, what would happen if you then write

cv.Last().DrawCircle(...)

You just called a DrawCircle method on a List<Button>.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

You need to add the Button control to the Children collection of the Canvas control like the following:

// Canvas myCanvas
Button myButton = new Button();
myButton.Content = "Press me";
myCanvas.Children.Add(myButton);

Have a look at this question to know how to add a Control in runtime.

Good luck!

Community
  • 1
  • 1
Homam
  • 23,263
  • 32
  • 111
  • 187