2010-06-03 10 views
6

WPF Visualizer Görsel Ağacı tuvalzaten başka Görsel bir çocuk veya bir CompositionTarget

canvas.Children.Add poli köküdür | Görsel Belirtilen>

görmezden

    olduğunu
  1. zaten bir Visual Basic veya
  2. bir KompozisyonTarget'in bir alt öğesi.

Bunun 1) olduğunu düşünmeyin, ne olduğundan emin değil 2) nedir? Visual Studio 2010 kullanarak

, F # 2.0, WPF, ... XAML değil

cevap

12

Bir alakalı kod örneği olmadan sorunu teşhis etmek biraz zor, ama belki sorun aynı çokgen eklemek çalıştı olmasıdır tuval 'iki kez çocuklara. Ben senin hata mesajı ile bunu çöker başka canvas.Children.Add poly eklerseniz

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() 

:

Bu

Ben senin hatayı yeniden kadar burped koddur.
canvas.Children.Add poly |> ignore 
canvas.Children.Add poly |> ignore //this fails, poly already exists on the canvas 

hatayı düzeltmek için, ben ilk bir yenisi ile değiştirilmesi amacıyla mevcuttu belirli çocuğu kaldırmak için canvas.Children.Remove çağırdı.

canvas.Children.Add poly |> ignore 
canvas.Children.Remove poly 
canvas.Children.Add poly |> ignore //this works, because the previous version is gone 

Bu sorununuzu düzeltir umuyoruz.

+0

Teşekkürler cfern. Şimdi WPF'de biraz daha uzağım. Geç yanıt için özür dilerim ... –

İlgili konular