WPF使用繪製圓形
阿新 • • 發佈:2021-12-01
繪製圓形
以下程式碼繪製的是一個黑色邊框的圓 可以通過StrokeThickness設定邊框的寬度。
<Grid> <!--圓型--> <Path Stroke="Black" Fill="White" StrokeThickness="4" HorizontalAlignment="Center" VerticalAlignment="Center" > <Path.Data > <EllipseGeometry Center="100,100" RadiusX="100" RadiusY="100" > </EllipseGeometry> </Path.Data> </Path> </Grid>
擴充套件同心圓
Ellipse 是用於繪製橢圓的,如果它的寬度和高度都相等那麼就變成了圓,這裡需要注意如果不給Zindex這個圓是在底層的是看不到的。
<Grid> <!--圓型--> <Ellipse Stroke="Red" StrokeThickness="1" Width="90" Height="90" Panel.ZIndex="1"/> <Path Stroke="Black" Fill="White" StrokeThickness="4" HorizontalAlignment="Center" VerticalAlignment="Center" > <Path.Data > <EllipseGeometry Center="100,100" RadiusX="100" RadiusY="100" > </EllipseGeometry> </Path.Data> </Path> </Grid>