次の方法で共有


方法: Polygon 要素を使用して閉じた図形を描画する

この例では、 Polygon 要素を使用して閉じた図形を描画する方法を示します。 閉じた図形を描画するには、 Polygon 要素を作成し、その Points プロパティを使用して図形の頂点を指定します。 最初と最後の点を結ぶ線が自動的に描画されます。 最後に、 FillStroke、またはその両方を指定します。

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 サンプル」を参照してください。