在WPF填充弧 [英] Filled Arcs in WPF

查看:562
本文介绍了在WPF填充弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一个图是这样的:



我需要为每一个弧线段,我可以处理事件,并重新着色,因为我需要一个独特的元素。我如何在WPF创建正确的几何形状有点不确定。我可以很容易地计算出四点从圆的半径,并从中心的角度每个弧段。使用100半径为内外圆和50,红色四点是(从左上角原产顺时针方向在圆的上方):

  0,0 
70,30
35,65
0.50

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





<预类=郎-xml prettyprint-覆盖> <路径行程=黑色填充=黑StrokeThickness =1>
< Path.Data>
<&的PathGeometry GT;
< PathGeometry.Figures>
<的PathFigure StartPoint可以=0,0>
< PathFigure.Segments>
< ArcSegment点=70,30/>
<线段点=35,65/>
< ArcSegment点=0,50/>
< /PathFigure.Segments>
< /&的PathFigure GT;
< /PathGeometry.Figures>
< /&的PathGeometry GT;
< /Path.Data>
< /路径和GT;



但是,这只是绘制与直线的梯形。我知道我可以改变的ArcSegments的大小,但我似乎无法弄清楚如何影响曲率。我想弧跟随主循环,但我不知道该如何表达。我怎样才能使电弧有合适的弧度?



另外,我该如何表达,并在C#代码添加路径的后面,而不是在XAML?


解决方案

我画正是那种形状(两个同轴圆弧和两个子午线加入他们)是这样的:

 新线段(新点(x2,y2),真),
新ArcSegment(新点(X3,Y3),新的尺寸( 100 * outerRadius,100 * outerRadius),0,largeAngle,SweepDirection.Clockwise,真),
新线段(新点(X4,Y4),真),
新ArcSegment(新点(X1, Y1),新的尺寸(100 * innerRadius,100 * innerRadius),0,largeAngle,SweepDirection.Counterclockwise,真),

显然,这代码,而不是XAML,但它可能给你踢启动。


I am trying to draw a figure something like this:

I need to have a unique element for each arc segment that I can handle events on and recolor as I need. I am a bit unsure on how to create the proper geometries in WPF. I can easily calculate the four points for each arc segment from the radius of the circles and the angle from center. Using a radius of 100 for the outer circle and 50 for the inner, the four points in red are (clockwise from top left with origin at top of circle):

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

Using these points I create a simple path to draw the segment:

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

But that just draws a trapezoid with straight lines. I know I can alter the Size on the ArcSegments, but I can't seem to figure out how that affects the curvature. I want the arcs to follow the main circle, but I am not sure how to express that. How can I make the arcs have the right curvature?

Also, how do I express and add paths in the c# code behind,rather than in the xaml?

解决方案

I've drawn exactly that sort of shape (two coaxial arcs and two radials joining them) like this:

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),

Obviously that's code rather than XAML, but it might give you a kick-start.

这篇关于在WPF填充弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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