方法: 複合図形を作成するHow to: Create a Composite Shape

この例を使用して複合図形を作成する方法を示しています。Geometryオブジェクトとそれらを表示を使用して、Path要素。This example shows how to create composite shapes using Geometry objects and display them using a Path element. 次の例では、 LineGeometryEllipseGeometryRectangleGeometryを併用、GeometryGroup複合図形を作成します。In the following example, a LineGeometry, EllipseGeometry, and a RectangleGeometry are used with a GeometryGroup to create a composite shape. ジオメトリを使用して描画し、Path要素。The geometries are then drawn using a Path element.

Example

<!-- Displays the geometry. --> 
<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>
// Create a Path to be drawn to the screen.
Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
SolidColorBrush mySolidColorBrush = new SolidColorBrush();
mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255);
myPath.Fill = mySolidColorBrush;

// Create the line geometry to add to the Path
LineGeometry myLineGeometry = new LineGeometry();
myLineGeometry.StartPoint = new Point(10, 10);
myLineGeometry.EndPoint = new Point(50, 30);

// Create the ellipse geometry to add to the Path
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
myEllipseGeometry.Center = new Point(40, 70);
myEllipseGeometry.RadiusX = 30;
myEllipseGeometry.RadiusY = 30;

// Create a rectangle geometry to add to the Path
RectangleGeometry myRectGeometry = new RectangleGeometry();
myRectGeometry.Rect = new Rect(30, 55, 100, 30);

// Add all the geometries to a GeometryGroup.
GeometryGroup myGeometryGroup = new GeometryGroup();
myGeometryGroup.Children.Add(myLineGeometry);
myGeometryGroup.Children.Add(myEllipseGeometry);
myGeometryGroup.Children.Add(myRectGeometry);

myPath.Data = myGeometryGroup;

// Add path shape to the UI.
StackPanel mainPanel = new StackPanel();
mainPanel.Children.Add(myPath);
this.Content = mainPanel;
' Create a Path to be drawn to the screen.
Dim myPath As New Path()
myPath.Stroke = Brushes.Black
myPath.StrokeThickness = 1
Dim mySolidColorBrush As New SolidColorBrush()
mySolidColorBrush.Color = Color.FromArgb(255, 204, 204, 255)
myPath.Fill = mySolidColorBrush

' Create the line geometry to add to the Path
Dim myLineGeometry As New LineGeometry()
myLineGeometry.StartPoint = New Point(10, 10)
myLineGeometry.EndPoint = New Point(50, 30)

' Create the ellipse geometry to add to the Path
Dim myEllipseGeometry As New EllipseGeometry()
myEllipseGeometry.Center = New Point(40, 70)
myEllipseGeometry.RadiusX = 30
myEllipseGeometry.RadiusY = 30

' Create a rectangle geometry to add to the Path
Dim myRectGeometry As New RectangleGeometry()
myRectGeometry.Rect = New Rect(30, 55, 100, 30)

' Add all the geometries to a GeometryGroup.
Dim myGeometryGroup As New GeometryGroup()
myGeometryGroup.Children.Add(myLineGeometry)
myGeometryGroup.Children.Add(myEllipseGeometry)
myGeometryGroup.Children.Add(myRectGeometry)

myPath.Data = myGeometryGroup

' Add path shape to the UI.
Dim mainPanel As New StackPanel()
mainPanel.Children.Add(myPath)
Me.Content = mainPanel

前の例で作成した図を次に示します。The following illustration shows the shape created in the previous example.

GeometryGroup を使用して作成された複合ジオメトリA composite geometry created using a GeometryGroup
複合ジオメトリComposite Geometry

使用して多角形と曲線のセグメントを持つ図形などのより複雑な図形を作成することがあります、PathGeometryします。More complex shapes, such as polygons and shapes with curved segments, may be created using a PathGeometry. 使用して図形を作成する方法を示す例については、PathGeometryを参照してくださいPathGeometry を使用して図形を作成です。For an example showing how to create a shape using a PathGeometry, see Create a Shape by Using a PathGeometry. この例を使用して、画面に図形をレンダリングしますが、Path要素、Geometryオブジェクトがの内容を記述することも可能性があります、GeometryDrawingまたはDrawingContextします。Although this example renders a shape to the screen using a Path element, Geometry objects may also be used to describe the contents of a GeometryDrawing or a DrawingContext. また、クリップのヒット テストも使用可能性があります。They may also be used for clipping and hit-testing.

この例は、より大きなサンプルの一部です。完全なサンプルについては、「ジオメトリのサンプル」を参照してください。This example is part of larger sample; for the complete sample, see the Geometries Sample.