You are calling:
rect = new System.Windows.Shapes.Rectangle(...);
And then:
canvas1.Children.Add(rect);
Which will add another new Rectangle
into your Canvas.Children
collection. If you want to remove the old one first, then call this first:
canvas1.Children.Remove(rect);