Search code examples
wpfxamldrawsystem.drawing

Draw circle with point on center - where


I want to draw a circle with a central point in XAML/WPF and use such code:

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

But the point is not placing in the center of the circle. Where did I make a mistake?


Solution

  • An Ellipse element isn't centered. Better use a Path element with an EllipseGeometry:

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