1

我想在 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") });
    }

在中间某处划线

4

2 回答 2

0

如果我使用 Canvas 而不是 ScatterView 和 ScatterViewItem 并且订单是这样的

 <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 ...

连接线的定位没有问题。

于 2012-11-28T14:12:28.733 回答
0

您的线路的起点和终点是您的 Startitem 的 ActualCenter.X/ActualCenter.Y。如果您的 Startitem 的 ActualCenter 为 10/100,您将在 10/100 到 10/100 之间画一条线,这就是您看不到任何线的原因。不要Source = Startitem在方法的最后两行设置,而是BindLineToScatterViewItems尝试设置Source = EndItem

希望这可以帮助。

于 2012-11-26T14:01:44.457 回答