views:

41

answers:

2

Hi guys. I really searched for a long time to get the clue how to add an instance of a custom UserControl Object, that I created to the Silverlight "stage", but I didn't find anything.

Is there anything in Silverlight with C# like "Stage.addChild(myAweseomeObject);" in Flash?

+2  A: 

From Jesse Liberty's page on Creating Controls in Code:

Button button2 = new Button(); 
button2.Width = 75; 
button2.Height = 30; 
button2.Content = "No, click me!"; 
button2.SetValue(Grid.RowProperty, 0); 
button2.SetValue(Grid.ColumnProperty, 1); 
LayoutRoot.Children.Add(button2);

You'd do the same thing with your own user control. Just replace "new Button()" with the name of your user control, e.g. "new MyUserControl()".

So a simplified version may be something like this:

AwesomeControl _AwesomeControl = new AwesomeControl();
LayoutRoot.Children.Add(_AwesomeControl);
Steve Wortham
thx =) exactly what I was looking for =)
A: 

Silverlight or Flash?

Flash has the addChild method.

oops.. I understood the question wrongly.

Amarghosh