此示例演示如何使用 Polygon 元素绘制封闭的形状。 若要绘制封闭的形状,请创建一个 Polygon 元素并使用其 Points 属性指定形状的顶点。 将自动绘制连接第一个和最后一个点的线条。 最后,指定一个 Fill、一个 Stroke或两者。
示例:
在可扩展应用程序标记语言(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>
尽管该示例使用 a Canvas 来包含多边形,但你可以将多边形元素(以及所有其他形状元素)与任何PanelControl或支持非文本内容的内容一起使用。
此示例是较大示例的一部分;有关完整示例,请参阅 形状元素示例。