1

How can I programmatically add UIElements to canvas in Silverlight 4?

But nothing happens. When I check for the existence of the image it is there but nothing shows.

wtf?

Button btn = new Button();
btn.Content = "Button";
Canvas.SetLeft(btn, 450);
Canvas.SetTop(btn, 100);
Canvas1.Resources.Add("btn1", btn);
Canvas1.UpdateLayout(); 
Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
marko
  • 10,684
  • 17
  • 71
  • 92

1 Answers1

3

You want to use Children, not Resources.

Button btn = new Button();
btn.Content = "Button";
Canvas.SetLeft(btn, 450);
Canvas.SetTop(btn, 100);
Canvas1.Children.Add(btn);
vcsjones
  • 138,677
  • 31
  • 291
  • 286