Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a semicircle / half circle in WPF / C#

I need to draw a semicircle / half circle in WPF. Any idea how to do that? Thanks for any hint!

like image 713
stefan.at.wpf Avatar asked Apr 22 '10 17:04

stefan.at.wpf


2 Answers

ArcSegment would be a good place to start.

And here is a good example of how to use it in code.

like image 62
Charlie Avatar answered Sep 20 '22 01:09

Charlie


Since the original link is dead, here's how I was able to draw an arc:

<Canvas>
    <Path Stroke="Gray">
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigureCollection>
                        <PathFigure StartPoint="0,20">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <ArcSegment Size="20, 20"
                                    IsLargeArc="True"
                                    SweepDirection="CounterClockwise"
                                    Point="40,20" />
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>
</Canvas>

That produces the following image (with added markings for some of the variables)

enter image description here

The XAML above is a modified version of the XAML found here:

https://www.c-sharpcorner.com/UploadFile/mahesh/drawing-arc-using-arcsegment-in-xaml/

like image 28
Victor Chelaru Avatar answered Sep 22 '22 01:09

Victor Chelaru