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