# Win10系列：C#应用控件进阶10

### EllipseGeometry

EllipseGeometry控件可以用于绘制椭圆，通过定义EllipseGeometry控件的Center属性确定椭圆的圆心坐标，使用此控件的RadiusX 和RadiusY属性分别定义椭圆X轴、Y轴的半径长度。下面将演示如何使用EllipseGeometry控件绘制一个椭圆。

<!--定义Path-->

<Path Fill="Yellow" Stroke="Black" StrokeThickness="5">

<Path.Data>

<EllipseGeometry Center="200,200" RadiusX="100" RadiusY="200">

</EllipseGeometry>

</Path.Data>

</Path>

public EllipseGeometryPage()

{

this.InitializeComponent();

//path前面加命名空间防止与System.IO.path 发生冲突

Windows.UI.Xaml.Shapes.Path mypath = new Windows.UI.Xaml.Shapes.Path();

mypath.Stroke = new SolidColorBrush(Colors.Black);

mypath.Fill = new SolidColorBrush(Colors.Yellow);

mypath.StrokeThickness = 3;

//实例化椭圆的对象

EllipseGeometry ellipseGeometry = new EllipseGeometry();

//设置圆心

ellipseGeometry.Center = new Point(200, 200);

//X轴半径为100px

ellipseGeometry.RadiusX = 100;

//Y轴半径为200px

ellipseGeometry.RadiusY = 200;

mypath.Data = ellipseGeometry;

MyShow.Children.Add(mypath);

}

### 8.3.4 GeometryGroup

<Path Fill="Orange" Stroke="Red" StrokeThickness="3">

<Path.Data>

<GeometryGroup FillRule="EvenOdd">

<EllipseGeometry Center="200,200" RadiusX="100" RadiusY="200"></EllipseGeometry>

<EllipseGeometry Center="250,200" RadiusX="100" RadiusY="200"></EllipseGeometry>

<EllipseGeometry Center="225,200" RadiusX="100" RadiusY="100"/>

</GeometryGroup>

</Path.Data>

</Path>

public GeometryGroupPage()

{

this.InitializeComponent();

//实例化Path类型的对象

Windows.UI.Xaml.Shapes.Path mypath = new Windows.UI.Xaml.Shapes.Path();

//设置mypath对象的属性

mypath.Stroke = new SolidColorBrush(Colors.Red);

mypath.StrokeThickness = 3;

mypath.Fill = new SolidColorBrush(Colors.Orange);

//实例化GeometryGroup类型的对象

GeometryGroup group = new GeometryGroup();

//实例化EllipseGeometry类型的对象

EllipseGeometry ellipseOne = new EllipseGeometry();

//设置椭圆的属性

ellipseOne.Center = new Point(200, 200);

//X轴半径为100px

ellipseOne.RadiusX = 100;

//Y轴半径为200px

ellipseOne.RadiusY = 200;

//定义另一个椭圆

EllipseGeometry ellipseTwo = new EllipseGeometry();

ellipseTwo.Center = new Point(250, 200);

ellipseTwo.RadiusX = 100;

ellipseTwo.RadiusY = 200;

EllipseGeometry ellipseThree = new EllipseGeometry();

ellipseThree.Center = new Point(225,200);

ellipseThree.RadiusX = 100;

ellipseThree.RadiusY = 100;

//设置填充规则

group.FillRule = FillRule.EvenOdd;

//添加椭圆到group控件中

group.Children.Add(ellipseOne);

group.Children.Add(ellipseTwo);

group.Children.Add(ellipseThree);

mypath.Data = group;

MyShow.Children.Add(mypath);

}

posted on 2017-03-30 21:20 冯为皓 阅读(...) 评论(...) 编辑 收藏