我正在构建一个小型Silverlight应用程序。在我的应用程序中,我需要绘制线条,类似于附图中显示的线条。
我知道绘制拱形连接线(绿色连接线)的最佳方法是使用贝塞尔曲线。
我的问题是,如何设置线条的绘制(让它们从起始(X,Y)坐标开始到目标坐标)?
附图:
答案 0 :(得分:4)
我花了一些时间玩这个,这是可能的。诀窍是你没有为路径设置动画。相反,您最初将路径剪切到零维度的边界区域,然后基本上为剪切区域的高度和宽度设置动画。最终效果看起来像路径从A点动画到B点。
看看下面的XAML示例:
<Canvas x:Name="LayoutRoot" Background="White">
<Path Stroke="Blue" StrokeThickness="2" StrokeDashArray="10,2" >
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigureCollection>
<PathFigure StartPoint="50,50">
<PathFigure.Segments>
<PathSegmentCollection>
<BezierSegment
Point1="50,20"
Point2="120,170"
Point3="350,150"
/>
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
<Path.Clip>
<PathGeometry>
<PathFigure IsClosed="true">
<LineSegment x:Name="seg1" Point="50,50"/>
<LineSegment x:Name="seg2" Point="0,0"/>
<LineSegment x:Name="seg3" Point="0,0"/>
<LineSegment x:Name="seg4" Point="0,0"/>
</PathFigure>
</PathGeometry>
</Path.Clip>
<Path.Triggers>
<EventTrigger RoutedEvent="Path.Loaded">
<BeginStoryboard>
<Storyboard>
<PointAnimation Storyboard.TargetName="seg2" Storyboard.TargetProperty="point" To="350,50" Duration="0:0:2" />
<PointAnimation Storyboard.TargetName="seg3" Storyboard.TargetProperty="point" To="350,150" Duration="0:0:2" />
<PointAnimation Storyboard.TargetName="seg4" Storyboard.TargetProperty="point" To="50,1500" Duration="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
<Path Fill="Gold" Stroke="Black" StrokeThickness="1">
<Path.Data>
<EllipseGeometry Center="50,50" RadiusX="20" RadiusY="20" />
</Path.Data>
</Path>
<Path Fill="Gold" Stroke="Black" StrokeThickness="1">
<Path.Data>
<EllipseGeometry Center="350,150" RadiusX="20" RadiusY="20" />
</Path.Data>
</Path>
</Canvas>