wpf 如何在 XAML 中绘制单独的圆圈?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21621305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to draw separate circle in XAML?
提问by Lê V?n Thành
How can I draw a circle like this, 2 colors in 2 parts. I'm coding in xaml
我怎样才能画一个这样的圆圈,2 种颜色的 2 部分。我正在用 xaml 编码


<Ellipse Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" Height="300">
</Ellipse>
<Path VerticalAlignment="Top" Fill="Brown" HorizontalAlignment="Left">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="59,150">
<ArcSegment SweepDirection="Clockwise" Size="141,80" Point="341,150"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
I try it, and the above Path not full a part 1. Help me try draw it!
我试了一下,上面的Path不完整a part 1.帮我试试画吧!
回答by Mark Feldman
Here ya go:
给你:
<Canvas>
<Ellipse Canvas.Left="50" Canvas.Top="50" Width="300" Height="300" Stroke="Black" StrokeThickness="1" Fill="Red" />
<Ellipse Canvas.Left="50" Canvas.Top="50" Width="300" Height="300" Stroke="Black" StrokeThickness="1" Fill="Yellow">
<Ellipse.Clip>
<RectangleGeometry Rect="0 100 300 300" />
</Ellipse.Clip>
</Ellipse>
<Rectangle Canvas.Left="50" Canvas.Top="150" Width="300" Height="200" Stroke="Black" StrokeThickness="1" Fill="Transparent">
<Rectangle.Clip>
<EllipseGeometry Center="150, 50" RadiusX="150" RadiusY="150" />
</Rectangle.Clip>
</Rectangle>
</Canvas>
The first canvas element draws a red circle, the second element draws a yellow circle over top and clips it, the third element draws the black line through the middle. Here's the result:
第一个画布元素绘制一个红色圆圈,第二个元素在顶部绘制一个黄色圆圈并将其剪辑,第三个元素绘制穿过中间的黑线。结果如下:


EDIT: Actually thinking about this some more the two ellipses can be done with a single ellipse and a linear gradient brush:
编辑:实际上再考虑一下这两个椭圆可以用一个椭圆和一个线性渐变画笔来完成:
<Ellipse Canvas.Left="50" Canvas.Top="50" Width="300" Height="300" Stroke="Black" StrokeThickness="1">
<Ellipse.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Red" Offset="0.3333" />
<GradientStop Color="Yellow" Offset="0.3333" />
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
回答by Sankarann
You can also make use of the following...
您还可以使用以下...
<Grid Height="200" Width="200" VerticalAlignment="Center">
<Ellipse Fill="#FFE1B631" />
<Path Data="M93.88768,0 C136.17198,0 172.32661,26.244247 186.95134,63.33252 L187.77536,65.5 0,65.5 0.82401276,63.33252 C15.44875,26.244247 51.603378,0 93.88768,0 z" Fill="#FFFD450F" Height="60.26" Stretch="Fill" VerticalAlignment="Top" Margin="8,1.31,8,0"/>
</Grid>



