此示例演示如何使用 Polygon 元素绘制闭合形状。 若要绘制闭合形状,请创建一个 Polygon 元素,并使用其 Points 属性指定形状的顶点。 系统将自动绘制一条线连接第一个点和最后一个点。 最后,指定 Fill 和/或 Stroke。
示例
在Extensible Application Markup Language (XAML) 中,点的有效语法是由逗号分隔的 x 和 y 坐标对组成的空格分隔的列表。
<Canvas Height="300" Width="300">
<!-- Draws a triangle with a blue interior. -->
<Polygon Points="10,110 60,10 110,110"
Fill="Blue" />
<!-- Draws a triangle with a blue interior and a black outline.
The Canvas.Top setting moves the Polygon down 150 pixels. -->
<Polygon Points="10,110 60,10 110,110"
Fill="Blue"
Stroke="Black" StrokeThickness="4"
Canvas.Top="150" />
<!-- Draws another triangle with a blue interior.
The Canvas.Left setting moves the Polygon 150 pixels to the right. -->
<Polygon Points="10,110 110,110 110,10"
Fill="Blue"
Canvas.Left="150" />
<!-- Draws a triangle with a black outline.
The Canvas.Left and Canvas.Top settings move
the Polygon down 150 pixels and 150 pixels to the right.-->
<Polygon Points="10,110 110,110 110,10"
Stroke="Black" StrokeThickness="4"
Canvas.Left="150" Canvas.Top="150" />
</Canvas>
虽然此示例使用 Canvas 来包含多边形,但您可以将多边形元素(及所有其他形状元素)与支持非文本内容的任何 Panel 或 Control 一起使用。
此示例摘自一个更大的示例;有关完整示例,请参见 Shape Elements Sample(Shape 元素示例)。