Itβs a little difficult to diagnose the problem without the appropriate code, but perhaps the problem is that you tried twice to add the same polygon to the children of the canvas.
This is the code I opened to reproduce your error:
type SimpleWindow() as this = inherit Window() do let makepoly size corners = let size = 192.0 let angle = 2.0 * Math.PI / float corners let getcoords size angle = new Point(size * cos angle, size * sin angle) let poly = new Polygon(Fill = Brushes.Red) poly.Points <- new PointCollection([for i in 0..corners-1 -> getcoords size (float i * angle)]) poly let canvas = new Canvas(HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center) let poly = makepoly 192.0 5 Canvas.SetLeft(poly, canvas.Width / 2.0) Canvas.SetTop(poly, canvas.Width / 2.0) canvas.Children.Add poly |> ignore
If I add another canvas.Children.Add poly , it will fail with your error message.
canvas.Children.Add poly |> ignore canvas.Children.Add poly |> ignore //this fails, poly already exists on the canvas
To fix the error, I first called canvas.Children.Remove to remove the specific child that was present, to replace it with another.
canvas.Children.Add poly |> ignore canvas.Children.Remove poly canvas.Children.Add poly |> ignore //this works, because the previous version is gone
Hope this fixes your issue.
cfern
source share