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
2010-07-06 15:44:12
@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
2010-07-06 15:59:22
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
2010-07-06 16:56:59