如何在 Silverlight 网格上放置椭圆?

发布于 2024-07-17 18:59:52 字数 519 浏览 6 评论 0原文

我正在创建一个 silverlight 应用程序,它允许您单击屏幕上的两个位置,并绘制一个椭圆,其主轴在单击位置开始和结束。 可单击区域是 Silverlight 网格控件。 当前:

当您第一次单击时,我是:

  1. 在单击时放置标记 观点。
  2. 创建一个椭圆并为其设置父子关系 到网格。
  3. 创建和设置 椭圆上的角度变换。

当您移动鼠标时,我正在:

  1. 计算到 第一个点击点。
  2. 将椭圆的宽度设置为 这个长度。
  3. 计算一条线的角度 单击点和网格的 X 轴。
  4. 将椭圆的 AngleTransform 角度设置为此角度。

到目前为止,一切都很好。 显示椭圆,其长度和旋转角度随着鼠标移动而变化。

但是,椭圆的长轴偏离了单击点。 如何定位椭圆,使其长轴从单击点开始,到当前鼠标位置结束?

I am creating a silverlight application which will allow you to click at two places on the screen and will draw an ellipse whose major axis starts and ends at the click locations. The clickable area is a Silverlight Grid control. Currently:

When you first click, I am:

  1. Dropping a marker at the click
    point.
  2. Creating an ellipse and parenting it
    to the Grid.
  3. Creating and setting an
    AngleTransform on the ellipse.

As you move the mouse, I am:

  1. Calculating the distance to the
    first click point.
  2. Setting the Width of the ellipse to
    this length.
  3. Calculating the angle of a line to
    the click point and the Grid's
    X-Axis.
  4. Setting the Ellipse's AngleTransform Angle to this angle.

So far, so good. The ellipse is displayed, and its length and angle of rotation follow the mouse as it moves.

However, the major axis of the ellipse is offset from the click point.
How do I position the Ellipse so its major axis starts at the click point and ends at the current mouse position?

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

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

发布评论

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

评论(3

葬シ愛 2024-07-24 18:59:52

答案是:

  • 不要使用System.Windows.Shapes.Ellipse。 请改用 System.Windows.Shapes.Path 并在其中嵌入 EllipseGeometry。

  • 还将 Path.RenderTransform 设置为 RotateTransform

  • 请勿在路径上设置宽度高度拉伸。 而是设置 EllipseGeometryCenterRadiusXRadiusY

  • 最后,将 RotateTransform.Angle 设置为 Ellipse 长轴和 X 轴的交叉角度(ArcTan的长轴斜率)。 还将 RotateTransform.CenterXCenterY 设置为 EllipseGeometry Center

The answer turned out to be:

  • Don't use System.Windows.Shapes.Ellipse. Instead use System.Windows.Shapes.Path and embed an EllipseGeometry in it.

  • Also set the Path.RenderTransform to a RotateTransform.

  • Don't set Width or Height or Stretch on the Path. Instead set the Center, RadiusX, and RadiusY of the EllipseGeometry.

  • Finally, set the RotateTransform.Angle to the angle of intersection of the Ellipse major-axis and the X-axis (the ArcTan of the major-axis slope). Also set RotateTransform.CenterX and CenterY to the EllipseGeometry Center.

风流物 2024-07-24 18:59:52

如果我不得不猜测(代码会有所帮助),我认为您可以从开始单击点的差异添加到网格左侧的填充,这应该有助于将其移动偏移量。

If I had to guess (code would help), I would think that you could add padding from the difference of the beginning click point to the left side of the grid, which should help move it over by the offset.

枫以 2024-07-24 18:59:52

对于您的应用程序来说,使用 Canvas 而不是网格可能是一个好主意,这样您就可以直接设置形状坐标。

May be it's a good idea to use Canvas instead of grid for your application, than you will be able to set up shapes coordianates directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文