用中心点绘制圆圈 - 在哪里

时间:2017-03-22 10:07:13

标签: wpf xaml draw system.drawing

我想在XAML / WPF中绘制一个带有中心点的圆圈并使用这样的代码:

        <Ellipse Name="Circle"
            Canvas.Left="4.88"
            Canvas.Top="15.095" 
            Width="9.14"
            Height="9.14"
            Stroke="Red"
            StrokeThickness="0.1" />

        <Ellipse Name="Point"
            Canvas.Left="9.2"
            Canvas.Top="19.415"  
            HorizontalAlignment="Center" 
            VerticalAlignment="Center"
            Width="0.5"
            Height="0.5"
            Fill="Red"
            Stroke="Red"
            StrokeThickness="0.1" />

但重点不在于圈子的中心。我在哪里弄错了?

1 个答案:

答案 0 :(得分:1)

Ellipse元素不居中。最好使用带有EllipseGeometry的Path元素:

<Path Name="Circle" Stroke="Red" StrokeThickness="0.1">
    <Path.Data>
        <EllipseGeometry Center="9.45,19.665" RadiusX="4.57" RadiusY="4.57"/>
    </Path.Data>
</Path>
<Path Name="Point" Fill="Red">
    <Path.Data>
        <EllipseGeometry Center="9.45,19.665" RadiusX="0.25" RadiusY="0.25"/>
    </Path.Data>
</Path>