은 관련 코드 샘플없이 문제를 진단하는 데 조금 어렵습니다,하지만 어쩌면 문제는 같은 다각형을 추가하려고한다는 것입니다 캔버스 아이들에게 두 번이나. 나는 당신의 오류 메시지와 함께 충돌 다른 canvas.Children.Add poly
를 추가하면
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 //this works
this.AddChild canvas |> ignore
SimpleWindow().Show()
:
이
내가 당신의 오류를 재현하도록 burped 코드입니다.
canvas.Children.Add poly |> ignore
canvas.Children.Add poly |> ignore //this fails, poly already exists on the canvas
오류를 해결하기 위해, 내가 먼저 다른에 의해 대체하기 위해 존재하는 특정 아이를 제거하는
canvas.Children.Remove
을했다.
canvas.Children.Add poly |> ignore
canvas.Children.Remove poly
canvas.Children.Add poly |> ignore //this works, because the previous version is gone
이 문제가 해결되기를 바랍니다.
감사합니다. 지금 WPF에 대해 좀 더 자세히 설명합니다. 늦은 응답에 대해 사과드립니다 ... –