WPF:如何绘制UML界面关系箭头?

时间:2011-02-15 20:03:21

标签: c# .net wpf

我想绘制以下箭头类型: enter image description here

我该怎么做?

我已经有类似的箭了:

private void InternalDrawArrowGeometry(StreamGeometryContext context)
        {
            double theta = Math.Atan2(Y1 - Y2, X1 - X2);
            double sint = Math.Sin(theta);
            double cost = Math.Cos(theta);

            Point pt1 = new Point(X1, this.Y1);
            Point pt2 = new Point(X2, this.Y2);

            Point pt3 = new Point(
                X2 + (HeadWidth * cost - HeadHeight * sint),
                Y2 + (HeadWidth * sint + HeadHeight * cost));

            Point pt4 = new Point(
                X2 + (HeadWidth * cost + HeadHeight * sint),
                Y2 - (HeadHeight * cost - HeadWidth * sint));

            context.BeginFigure(pt1, true, false);
            context.LineTo(pt2, true, true);
            context.LineTo(pt3, true, true);
            context.LineTo(pt4, true, true);
            context.LineTo(pt2, true, true);
        }

我如何更改,这不是箭头而是圆圈?

1 个答案:

答案 0 :(得分:1)

在垂直StackPanel中使用椭圆形和垂直线(Horizo​​ntalAlignment设置为居中)。那就是:

  <StackPanel>   
    <Ellipse HorizontalAlignment="Center" Height="10" Width="10" 
             Stroke="Black" />
    <Line HorizontalAlignment="Center" X1="0" Y1="0" X2="0" Y2="10" 
             Stroke="Black" />
    <Rectangle Width="40" Height="20" Stroke="Black"/>
  </StackPanel>

我还在那里抛出一个Rectangle来表示实现接口的类。