2012-11-26 55 views
1

我想在ScatterViewItems之間畫線,但它不適用於我已經在這裏找到的東西。有一條線,但沒有連接到橢圓的中心。有人看到我的錯誤嗎?以下是我有:用線連接ScatterViewItems

<Grid> 
    <s:ScatterView> 
     <s:ScatterViewItem Height="250" Width="500" Background="Transparent" Orientation="0" HorizontalAlignment="Right" Margin="0,70,-764,-70" d:LayoutOverrides="HorizontalAlignment, Width"> 
      <s:ScatterView Height="250" Width="500" Background="BlueViolet"> 
       <s:ScatterViewItem Background="Transparent" Center="100,145" Orientation="0"> 
        <Label Content="Knoten A" Background="WhiteSmoke" Foreground="Black"/> 
       </s:ScatterViewItem> 
       <s:ScatterViewItem x:Name="StartItem" CanMove="False" CanRotate="False" Margin="0" Center="10,125" Background="Transparent"> 
        <Ellipse Width="10" Height="10" Fill="Transparent" Stroke="Black" Margin="0,0,0,0"/> 
       </s:ScatterViewItem> 
       <s:ScatterViewItem x:Name="EndItem" CanMove="False" CanRotate="False" Margin="0" Center="490,125" Background="Transparent"> 
        <Ellipse Width="10" Height="10" Fill="Transparent" Stroke="Black" Margin="0,0,0,0"/> 
       </s:ScatterViewItem> 
       <s:ScatterViewItem Background="Transparent"> 
        <Canvas Name="LineHost"/> 
       </s:ScatterViewItem> 
      </s:ScatterView> 
     </s:ScatterViewItem> 
    </s:ScatterView> 
</Grid> 

和C#

Line line = new Line { Stroke = Brushes.Black, StrokeThickness = 2.0 }; 
     BindLineToScatterViewItems(line, StartItem, EndItem); 
     LineHost.Children.Add(line); 

private void BindLineToScatterViewItems(Line line, ScatterViewItem StartItem, ScatterViewItem EndItem) 
    { 
     BindingOperations.SetBinding(line, Line.X1Property, 
            new Binding {Source = StartItem, Path = new PropertyPath("ActualCenter.X")}); 
     BindingOperations.SetBinding(line, Line.Y1Property, 
            new Binding { Source = StartItem, Path = new PropertyPath("ActualCenter.Y") }); 

     BindingOperations.SetBinding(line, Line.X2Property, 
            new Binding { Source = EndItem, Path = new PropertyPath("ActualCenter.X") }); 
     BindingOperations.SetBinding(line, Line.Y2Property, 
            new Binding { Source = EndItem, Path = new PropertyPath("ActualCenter.Y") }); 
    } 

line somewhere in the middle

回答

0

的起始點和端點從你的臺詞是你的起始物品的ActualCenter.X/ActualCenter.Y。如果您的Startitem的ActualCenter爲10/100,則會繪製一條從10/100到10/100的線條,這是您看不到任何線條的原因。 而不是在BindLineToScatterViewItems方法的最後兩行中設置Source = Startitem,請嘗試設置Source = EndItem

希望這會有所幫助。

+0

謝謝,我剛剛也看到了它;-)現在這條線在那裏,但沒有連接到橢圓。任何想法爲什麼? – Judith

+0

你可以發佈它的截圖嗎? ;) –

+0

很抱歉,作爲垃圾郵件防範機制,新用戶不允許發佈圖片。獲得超過10個聲望來發布圖像。 ^^ – Judith

0

如果我用帆布代替ScatterView和ScatterViewItem和秩序IST的這樣

<s:ScatterView> 
     <Canvas Name="LineCanvas2" Width="500" Height="250" Background="Aquamarine"> 
      <Canvas Background="Transparent" Name="LineCanvas"/> 
      <s:ScatterView Width="500" Height="250" Background="Transparent"> 
       <s:ScatterViewItem ... 

還有與連接線的位置沒有問題。