Partilhar via


Point

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.

<object property = "pointString" ... />
object.property = "pointString"

pointString Grammar

X,Y

-or-

X Y

  • X is the horizontal (x) point position in pixels. Y is the vertical (y) point position in pixels.

  • X and Y can be negative, with the result that the Rect definition is off the screen, unless there is additional translation.

  • X and Y can be noninteger values in terms of permitted values, but they are interpreted as integers regardless during rendering.

  • You can use a space rather than a comma as the delimiter between X and Y.

Managed Equivalent

Point

Remarks

The Point object parallels a convention that is supported by a type converter, such that properties that take a Point as their value can specify a Point as a formatted string. The type converter generates a new Point value based on processing the string. The type converter functions for use in both XAML and script. In both cases, you supply a quoted string. The format of that string is an X,Y value pair.

X and Y can be noninteger values in terms of permitted values, but are interpreted as integers regardless during rendering. In general, you should not use noninteger values. In particular, the comma used as the X,Y separator in the type converter behavior will clash with cultural uses in which the comma is the decimal separator if that value is entered as a string.

Point is the type that is returned from a call to the GetPosition method used in mouse event handlers. Also, a Point is used for some properties, such as To and From, of a PointAnimation object. For these cases, Point is a true object. You can get X values from the GetPosition return value, but you cannot set them. You can get and set X and Y values from a PointAnimation property.

Point is also used extensively as a property value in geometry-related objects and for the InkPresenter object. If you attempt to get values through scripting for these Point values, the GetValue method call will fail. This is because the JavaScript API does not use Point as a true object for these particular properties, and the type conversion behavior does not provide a reverse conversion to provide a ToString or other value representation to the object model.

In scripting, it is generally true that you cannot construct a new Silverlight object based on a constructor. However, for types that have type converter support, you can use the type converter behavior to generate the object from a convertible type—in this case a string. Therefore, in order to generate a Point value in script, you must target a property that takes a Point (such as EndPoint in the example).

Example

The following example generates a Point by targeting an EndPoint value. In the example, myPath is a Path previously defined in XAML, and the function is attached to a Canvas root as a mouse event handler.

function moveLine(sender, args) {
   myPath = sender.findName("myPath");
   myPath.Data.EndPoint = "250,150";
}