It is not enough to add, it is also necessary that it is drawn. By sabzh found an example
var rectangle = new Rectangle(); rectangle.Fill = Brushes.Red; rectangle.Width = 100; rectangle.Height = 100; Canvas.SetLeft(rectangle, 0); Canvas.SetTop(rectangle, 0); canvas1.Children.Add(rectangle);
In the property of canvas1 itself, the element lies, but displays nothing on the screen.
Maybe the element properties in the XAML itself need to be adjusted? Or how else can you solve this problem?