Compartilhar via


Sintaxe de Marcação de Caminho

Paths are discussed in Visão geral de Formas e Desenho básico no WPF and the Visão Geral de Geometria, however, this topic describes in detail the powerful and complex mini-language you can use to specify path geometries more compactly using Extensible Application Markup Language (XAML).  

This topic contains the following sections.

Prerequisites

To understand this topic, you should be familiar with the basic features of Geometry objects. Para obter mais informações, consulte o Visão Geral de Geometria.

StreamGeometry and PathFigureCollection Mini-Languages

WPFfornece duas classes que fornecem os idiomas mini-para descrever geométricos caminhos: StreamGeometry and PathFigureCollection.

  • You use the StreamGeometry mini-language when setting a property of type Geometry, such as the Clip property of a UIElement or the Data property of a Path element. The following example uses attribute syntax to create a StreamGeometry.

    <Path Stroke="Black" Fill="Gray"
          Data="M 10,100 C 10,300 300,-200 300,100" />
    
  • You use the PathFigureCollection mini-language when setting the Figures property of a PathGeometry. The following example uses a attribute syntax to create a PathFigureCollection for a PathGeometry.

    <Path Stroke="Black" Fill="Gray">
      <Path.Data>
        <PathGeometry Figures="M 10,100 C 10,300 300,-200 300,100" />
      </Path.Data>
    </Path>
    

As you can see from the preceding examples, the two mini-languages are very similar. It's always possible to use a PathGeometry in any situation where you could use a StreamGeometry; so which one should you use? Use a StreamGeometry when you don't need to modify the path after creating it; use a PathGeometry if you do need to modify the path.

For more information about the differences between PathGeometry and StreamGeometry objects, see the Visão Geral de Geometria.

A Note about White Space

For brevity, a single space is shown in the syntax sections that follow, but multiple spaces are also acceptable wherever a single space is shown.

Two numbers don’t actually have to be separated by a comma or whitespace, but this can only be done when the resulting string is unambiguous. Por exemplo, 2..3 é na verdade dois números: "2." E ". 3". Da mesma forma, 2-3 é "2" e "-" (3). Spaces are not required before or after commands, either.

Syntax

The Extensible Application Markup Language (XAML) attribute usage syntax for a StreamGeometry is composed of an optional FillRule value and one or more figure descriptions.

StreamGeometry XAML Attribute Usage

<objeto propriedade="fillRulefigureDescriptionfigureDescription]*" ... />

The Extensible Application Markup Language (XAML) attribute usage syntax for a PathFigureCollection is composed of one or more figure descriptions.

PathFigureCollection XAML Attribute Usage

<objeto propriedade="figureDescriptionfigureDescription]*" ... />

Term

Description

fillRule

System.Windows.Media.FillRule

Specifies whether the StreamGeometry uses the EvenOdd or Nonzero FillRule.

  • F0 specifies the EvenOdd fill rule.

  • F1 specifies the Nonzero fill rule.

If you omit this command, the subpath uses the default behavior, which is EvenOdd. If you specify this command, you must place it first.

figureDescription

A figure composed of a move command, draw commands, and an optional close command.

moveCommanddrawCommands [closeCommand]

moveCommand

A move command that specifies the start point of the figure. See the Move Command section.

drawCommands

One or more drawing commands that describe the figure's contents. See the Draw Commands section.

closeCommand

An optional close command that closes figure. See the Close Command section.

Move Command

Specifies the start point of a new figure.

Syntax

M startPoint

- or -

m startPoint

Term

Description

startPoint

System.Windows.Point

The start point of a new figure.

maiúsculasM indica que startPoint é um valor absoluto; um em minúsculas m indica que startPoint é um deslocamento para o ponto anterior, ou (0,0) se não houver nenhum. If you list multiple points after the move command, a line is drawn to those points though you specified the line command.

Draw Commands

A draw command can consist of several shape commands. Os comandos de forma a seguir estão disponíveis: linhahorizontal linha, vertical linha, curva de Bezier cúbica, curva de Bezier quadrática, curva de Bezier cúbica suave, curva de Bezier quadrática suave e arco elíptico.

Cada comando digitado usando uma letra em minúsculas ou maiúsculas : letrasmaiúsculas indicam valores absolutos e letras em minúsculas denotam valores relativos: os pontos de controle para esse segmento são relativo ao ponto final do exemplo anterior. When sequentially entering more than one command of the same type, you can omit the duplicate command entry; for example, L 100,200 300,400 is equivalent to L 100,200 L 300,400. The following table describes the move and draw commands.

Line Command

Cria uma linha reta entre o ponto atual e o ponto de extremidade especificado. l 20 30e L 20,30 são exemplos de válido line comandos.

Syntax

L ponto de extremidade

- or -

l ponto de extremidade

Term

Description

ponto de extremidade

System.Windows.Point

The end point of the line.

Horizontal Line Command

Cria uma linha horizontal entre o ponto atual e o especificado coordenada X. H 90é um exemplo de um comando de linha de horizontal válido .

Syntax

H x

- or -

h x

Term

Description

x

System.Double

The x-coordinate of the end point of the line.

Vertical Line Command

Cria uma linha vertical entre o ponto atual e a coordenada y especificado-. v 90é um exemplo de um comando de linha de vertical válido .

Syntax

V y

- or -

v y

Term

Description

y

System.Double

The y-coordinate of the end point of the line.

Cubic Bezier Curve Command

Cria uma curva de Bezier cúbica entre o ponto atual e o ponto de extremidade especificado, usando os dois pontos de controle especificado (controlPoint1 e controlPoint2). C 100,200 200,400 300,200é um exemplo de um comando válido da curva.

Syntax

C controlPoint1 controlPoint2 endPoint

- or -

c controlPoint1 controlPoint2 endPoint

Term

Description

controlPoint1

System.Windows.Point

The first control point of the curve, which determines the starting tangent of the curve.

controlPoint2

System.Windows.Point

The second control point of the curve, which determines the ending tangent of the curve.

endPoint

System.Windows.Point

The point to which the curve is drawn.

Quadratic Bezier Curve Command

Cria uma curva de Bezier quadrática entre o ponto atual e o ponto de extremidade especificado usando o ponto de controle especificado (controlPoint). q 100,200 300,200é um exemplo de um comando de curva de Bezier quadrático válido .

Syntax

Q controlPoint endPoint

- or -

q controlPoint endPoint

Term

Description

controlPoint

System.Windows.Point

The control point of the curve, which determines the starting and ending tangents of the curve.

endPoint

System.Windows.Point

The point to which the curve is drawn.

Smooth cubic Bezier curve Command

Creates a cubic Bezier curve between the current point and the specified end point. The first control point is assumed to be the reflection of the second control point of the previous command relative to the current point. If there is no previous command or if the previous command was not a cubic Bezier curve command or a smooth cubic Bezier curve command, assume the first control point is coincident with the current point. The second control point, the control point for the end of the curve, is specified by controlPoint2. For example, S 100,200 200,300 is a valid smooth cubic Bezier curve command.

Syntax

S controlPoint2 endPoint

- or -

s controlPoint2 endPoint

Term

Description

controlPoint2

System.Windows.Point

The control point of the curve, which determines the ending tangent of the curve.

endPoint

System.Windows.Point

The point to which the curve is drawn.

Smooth quadratic Bezier curve Command

Creates a quadratic Bezier curve between the current point and the specified end point. The control point is assumed to be the reflection of the control point of the previous command relative to the current point. If there is no previous command or if the previous command was not a quadratic Bezier curve command or a smooth quadratic Bezier curve command, the control point is coincident with the current point.

Syntax

T controlPoint endPoint

- or -

t controlPoint endPoint

Term

Description

controlPoint

System.Windows.Point

The control point of the curve, which determines the starting and tangent of the curve.

endPoint

System.Windows.Point

The point to which the curve is drawn.

Elliptical Arc Command

Creates an elliptical arc between the current point and the specified end point.

Syntax

A size rotationAngle isLargeArcFlag sweepDirectionFlag endPoint

- or -

a size rotationAngle isLargeArcFlag sweepDirectionFlag endPoint

Term

Description

size

System.Windows.Size

The x- and y-radius of the arc.

rotationAngle

System.Double

The rotation of the ellipse, in degrees.

isLargeArcFlag

Set to 1 if the angle of the arc should be 180 degrees or greater; otherwise, set to 0.

sweepDirectionFlag

Set to 1 if the arc is drawn in a positive-angle direction; otherwise, set to 0.

endPoint

System.Windows.Point

The point to which the arc is drawn.

The Close Command

Ends the current figure and creates a line that connects the current point to the starting point of the figure. This command creates a line-join (corner) between the last segment and the first segment of the figure.

Syntax

Z

- or -

z

Point Syntax

Describes the x- and y-coordinates of a point.

Syntax

x,y

- or -

x y

Term

Description

x

System.Double

The x-coordinate of the point.

y

System.Double

The y-coordinate of the point.

Special Values

Instead of a standard numerical value, you can also use the following special values. These values are case-sensitive.

You may also use scientific notation. For example, +1.e17 is a valid value.

Consulte também

Referência

Path

StreamGeometry

PathGeometry

PathFigureCollection

Conceitos

Visão geral de Formas e Desenho básico no WPF

Visão Geral de Geometria

Outros recursos

Geometries How-to Topics