如何在XAML中绘制单独的圆圈?

时间:2014-02-07 07:02:45

标签: wpf xaml windows-phone

如何画这样的圆圈,2个颜色分为2个部分。我在xaml编码

enter image description here

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

我尝试了,上面的路径没有完整的部分1.帮我试试吧!

2 个答案:

答案 0 :(得分:17)

这里你去:

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

第一个画布元素绘制一个红色圆圈,第二个元素在顶部绘制一个黄色圆圈并剪切它,第三个元素在中间绘制黑色线条。结果如下:

enter image description here

编辑:实际上考虑到这一点,可以用一个椭圆和一个线性渐变画笔完成两个椭圆:

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

答案 1 :(得分:4)

您还可以使用以下内容......

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

enter image description here