首页 文章

WPF中的填充弧

提问于
浏览
5

我想画一个像这样的数字:
Concentric arcs

我需要为每个弧段提供一个独特的元素,我可以根据需要处理事件和重新着色 . 我对如何在WPF中创建适当的几何图形有点不确定 . 我可以从圆的半径和中心的角度轻松计算每个弧段的四个点 . 外圆的半径为100,内圆的半径为50,红色的四个点(从左上角顺时针,原点在圆的顶部):

0,0
70,30
35,65
0,50

使用这些点我创建了一个绘制段的简单路径:

<Path Stroke="Black" Fill="Black" StrokeThickness="1" >
  <Path.Data>
    <PathGeometry>
      <PathGeometry.Figures>
        <PathFigure StartPoint="0,0">
          <PathFigure.Segments>
            <ArcSegment Point="70,30" />
            <LineSegment Point="35,65" />
            <ArcSegment Point="0,50" />
          </PathFigure.Segments>
        </PathFigure>
      </PathGeometry.Figures>
    </PathGeometry>
  </Path.Data>
</Path>

但这只是绘制一条直线的梯形 . 我知道我可以改变ArcSegments上的尺寸,但我似乎无法弄清楚它是如何影响曲率的 . 我希望弧线跟随主圈,但我不知道如何表达 . 如何使圆弧具有正确的曲率?

另外,如何在c#代码后面而不是在xaml中表达和添加路径?

2 回答

  • 0

    我已经准确地绘制了这种形状(两个同轴圆弧和两个连接它们的径向),如下所示:

    new LineSegment(new Point(x2, y2), true),
    new ArcSegment(new Point(x3,y3),new Size(100*outerRadius,100*outerRadius), 0,largeAngle, SweepDirection.Clockwise, true),
    new LineSegment(new Point(x4, y4), true),
    new ArcSegment(new Point(x1, y1),new Size(100*innerRadius,100*innerRadius), 0,largeAngle, SweepDirection.Counterclockwise, true),
    

    显然这是代码而不是XAML,但它可能会给你一个启动 .

  • 5

    另一个选项可以是将表达式2010绘图命名空间引入XAML . 它让事情变得简单 .

    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="Arcs.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ed:Arc ArcThickness="30"
                ArcThicknessUnit="Pixel"
                StartAngle="30"
                EndAngle="130"
                HorizontalAlignment="Left"
                Height="179" Margin="195,62,0,0"
                Stretch="None"
                Stroke="CornflowerBlue"
                Fill ="CornflowerBlue"
                VerticalAlignment="Top"
                Width="179" />
    </Grid>
    

    编辑:这将拉入安装Blend时安装的“Microsoft.Expression.Drawing” . 如果客户端计算机没有这个,那么这将失败 . 另一方面,您可以使用软件打包和重新分发dll . 微软允许这样做 .

相关问题