Silverlight - 如何画一条带弧线的线?

发布于 2024-10-29 16:31:09 字数 400 浏览 1 评论 0原文

我正在开发一个小型 silverlight 应用程序(使用 siverlight 4 和 c#)。在我的应用程序中,我需要根据 X、Y 绘制坐标。然后,我需要根据一些点之间的连接在它们之间画线。由于可能有多条线,而且我不能让它们全部相互交叉(因为这会让这变得一团糟),所以我需要用拱形画一些线。

那么,解决这个问题的最佳方法是什么?

  • 创建我自己的 x,y 系统 - 将元素定位在点中并绘制线 - 如果是这样,我如何绘制带有拱形的线?
  • 使用提供类似功能的现成控件?如果是的话,用什么控制?

谢谢你!

附上一张小图片来说明我的需求(抱歉,我不是大画家)。

在此处输入图像描述

I am developing a small silverlight application (using siverlight 4 and c#). In my application I need to draw coordinates based on their X,Y. Then, I need to draw lines between some of the points, based on the connections between them. Since there can be several lines, and I cannot have them all intersecting each other (as it will turn this into a mess), I need to draw some of my lines with an arch.

So, What would be the best way to approach this issue?

  • Create my own x,y system - position elements in points and draw lines - If so How can I draw a line with an arch?
  • Use a ready control that provides similar capabilities? If so, what control?

Thank You!

Attached is a small image to illustrate my need (I am no big painter, sorry).

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的夜不怕黑 2024-11-05 16:31:09

看一下绘制贝塞尔曲线 (MSDN 链接)并了解不同的几何类型(MSDN 链接

下面是一个可帮助您入门的代码示例,它将生成以下图像:
贝塞尔曲线示例

<Canvas x:Name="LayoutRoot" Background="White">
        <Path Stroke="Blue" StrokeThickness="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>
        <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>

Take a look at drawing Bezier curves (MSDN Link) and learn about the different geometry types (MSDN Link)

Below is a code sample to get you started that will produce the following image:
Bezier Curve Sample

<Canvas x:Name="LayoutRoot" Background="White">
        <Path Stroke="Blue" StrokeThickness="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>
        <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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文