2012-11-26 28 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 ... 

还有与连接线的位置没有问题。