连接ScatterViewItems带线 [英] Connecting ScatterViewItems with a line

查看:111
本文介绍了连接ScatterViewItems带线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请ScatterViewItems之间的线,但它并没有什么我已经在这里找到了工作。有一个线,但不连接到椭圆的中心。是否有人看到我的错误?以下是我有:

I want to draw lines between ScatterViewItems but it doesn't work with what I already found here. There is a Line, but not connected to the center of the ellipses. Does anybody see my mistake? Here is what I have:

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

推荐答案

如果我用,而不是ScatterView和ScatterViewItem以及订单IST这样的帆布

If I use Canvas instead of ScatterView and ScatterViewItem and the order ist like this

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

有与连接线的定位没有问题。

there is no problem with the positioning of the connection lines.

这篇关于连接ScatterViewItems带线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆