Silverlight图形学习笔记(四):几何图形

本文详细介绍了如何在XAML中使用Geometry对象描绘二维形状,包括简单的几何图形(如直线、矩形、椭圆)和路径几何图形,以及如何创建复合几何图形。通过实例展示了如何设置Geometry对象的不同属性来呈现不同的形状。
<UserControl x:Class="SharpStudy.GeometryDemo"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable
="d"
d:DesignHeight
="300" d:DesignWidth="400">
<!--

(一)Geometry 对象可以用于描绘二维 (2-D) 形状的几何图形
(二)Geometry 与 Shape 的比较
(1)相似点:描绘二维形状
(2)不同点:
Shape对象是UIElement(所以具有UIElement具有的 Opacity、OpacityMask等属性)
通过使用 Geometry 设置 Path 的 Data 属性以及设置它的 Fill 和 Stroke 属性,可以呈现 Geometry。
(三)Geometry 对象分类:
简单几何图形:
(1)LineGeometry:过指定直线的起点(StartPoint)和终点(EndPoint)来定义
(2)RectangleGeometry 通过使用 Rect 结构来定义。RadiusX 和 RadiusY 属性来创建圆角矩形。
(3)EllipseGeometry 通过中心点(Center)、x 半径( RadiusX)和 y 半径(RadiusY)来定义。
路径几何图形:PathGeometry 对象和几何图形 mini-language 提供了描绘由弧线、曲线和直线组成的多个复杂图形的方法。

复合几何图形:可以使用 GeometryGroup 对象来创建复合几何图形对象。GeometryGroup 创建它所包含的 Geometry 对象的组合体,但不合并其面积



-->
<StackPanel Orientation="Horizontal">
<!--简单几何图形-->
<!--LineGeometry-->
<Canvas>
<Path Stroke="Black" StrokeThickness="1" >
<Path.Data>
<LineGeometry StartPoint="10,20" EndPoint="100,130" />
</Path.Data>
</Path>
</Canvas>
<!--EllipseGeometry-->
<Canvas>
<Path Fill="Gold" Stroke="Black" StrokeThickness="1">
<Path.Data>
<EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" />
</Path.Data>
</Path>
</Canvas>
<!--RectangleGeometry-->
<Canvas>
<Path Fill="LemonChiffon" Stroke="Black" StrokeThickness="1">
<Path.Data>
<RectangleGeometry Rect="50,50,25,25" RadiusX="10" RadiusY="10" />
</Path.Data>
</Path>
</Canvas>

<!--
路径几何图形
(1)PathGeometry 的核心是 PathFigure 对象的集合;这些对象之所以这样命名是因为每个图形都描绘 PathGeometry 中的一个离散形状
(2) 每个 PathFigure 自身又由一个或多个 PathSegment 对象组成,每个这样的对象均描绘图形的一条线段。
(3)路径标记语法:Geometry 对象支持使用一系列特殊的移动和绘制命令的 XAML 属性语法
-->
<Canvas>
<Path Stroke="Black" StrokeThickness="1">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="10,20">
<PathFigure.Segments>
<LineSegment Point="100,130"/>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
<!--
复合几何图形
-->
<Canvas>
<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
<Path.Data>

<!-- Creates a composite shape from three geometries. -->
<GeometryGroup FillRule="EvenOdd">
<LineGeometry StartPoint="10,10" EndPoint="50,30" />
<EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" />
<RectangleGeometry Rect="30,55 100 30" />
</GeometryGroup>
</Path.Data>
</Path>
</Canvas>

</StackPanel>
</UserControl>

转载于:https://www.cnblogs.com/Joetao/articles/2064231.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值