views:

28

answers:

1

How can I create an instance of my UserControl dynamically (in code behind) and display it on the Canvas?

A: 
YourUserControlClassName myUC = new YourUserControlClassName();
myCanvas.Children.Add(myUC);

If myCanvas is not dynamic and is in xaml then you need this to get the reference myCanvas

Canvas myCanvas = (Canvas)this.FindName("CanvasNameInXaml");
Veer
@JooLio: Although this solves your problem, this is a bad approach. If you portray the scenario better, I would try to suggest a better design.
Veer
Canvas has Name attribute. I can use it in my code by name. But I didn't know I can get control by it's String name o_O. That may be very usefull.
JooLio