KMC
KMC

Reputation: 20036

How to define a Control properties in a List

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?

Upvotes: 0

Views: 212

Answers (2)

Homam
Homam

Reputation: 23871

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!

Upvotes: 1

SLaks
SLaks

Reputation: 887797

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>.

Upvotes: 1

Related Questions